TexasJJJJJ
TexasJJJJJ

Reputation: 33

Escaping colon ":" in Hibernate/Postgres/JSON

I am trying to build up an HQL query that uses the postgress json search capabilities.

In straight SQL, the following works as expected:

sb.append("select...<blah>, regexp_split_to_table(fe.meta::json->>'elementName', ',') ...

I have tried every combination of escaping that "::json" I can find on the web.

sb.append("select...<blash>, regexp_split_to_table(fe.meta\\:\\:json->>'elementName', ',') ...

:\\:
\\::

using !:!: and then adding escape !

Regardless of the combinations, I either get invalid query, not all named parameters have been set or Space is not allowed after parameter prefix

Is there any other method out there?

Any help greatly appreciated!

Upvotes: 2

Views: 1509

Answers (1)

mu is too short
mu is too short

Reputation: 434845

x::json is just a PostgreSQL-specific way of casting x to json, you don't have to use the :: syntax if you don't want to or if you can't because someone wants to use colons for named parameters. You can always use a plain old standard cast instead:

cast(fe.meta as json)->>'elementName'

Upvotes: 4

Related Questions