PostgreSQL knows a couple of funky ASCII-art operators that use the question mark character in their names, for instance these JSON operators:
?
does the string exist as a top-level key within the JSON value??|
Do any of these array strings exist as top-level keys??&
Do all of these array strings exist as top-level keys?
The problem is that the official PostgreSQL JDBC driver does not seem to correctly parse SQL strings containing such operators. It assumes that the question mark is an ordinary JDBC bind variable. The following code...
try (PreparedStatement s = c.prepareStatement("select '{}'::jsonb ?| array['a', 'b']");
ResultSet rs = s.executeQuery()) {
...
}
... throws an exception:
org.postgresql.util.PSQLException: Für den Parameter 1 wurde kein Wert angegeben.
at org.postgresql.core.v3.SimpleParameterList.checkAllParametersSet(SimpleParameterList.java:225)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:190)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:424)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:161)
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:114)
How can I use this operator?