Re: State of the support for the hstore ? operator

From: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "'Thomas Kellerer *EXTERN*'" <spam_eater(at)gmx(dot)net>, "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: State of the support for the hstore ? operator
Date: 2015-11-18 10:35:23
Message-ID: A737B7A37273E048B164557ADEF4A58B50FE7023@ntex2010i.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Thomas Kellerer wrote:
> I just stumbled upon this (using postgresql-9.4-1205.jdbc42.jar)
>
> Statement stmt = con.createStatement();
> ResultSet rs = stmt.executeQuery("select count(*) from product where attributes ? 'location_id'");
>
> results in
>
> org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
>
> "product.attributes" is a hstore column:
>
> I recall a discussion about this problem a while ago, but I can't find it any more.
>
> While I certainly would expect a problem when using a PreparedStatement I am surprised
> that a "plain" executeQuerys() also tries to do parameter replacement.
>
> I have found the suggestion to use exist(attributes, 'location_id') but that is not
> an option as that does not use the index on the column.
>
> So what is the state of this? Do we have a way of escaping the ? operator?
>
> I couldn't find anything in the documentation.

I looked into the source, and you can escape the question mark by doubling it.

But I agree that it is strange that the JDBC driver substitutes question marks
with positional parameters in that case.

I think that is a bug in org/postgresql/core/Parser: Even if "withParameters"
is false, it parses question marks.

I'll try to come up with a patch.

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Thomas Kellerer 2015-11-18 10:53:54 Re: State of the support for the hstore ? operator
Previous Message Thomas Kellerer 2015-11-18 07:44:04 State of the support for the hstore ? operator