pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
State of the support for the hstore ? operator
5+ messages / 2 participants
[nested] [flat]

* State of the support for the hstore ? operator
@ 2015-11-18 07:44 Thomas Kellerer <spam_eater@gmx.net>
  2015-11-18 10:35 ` Re: State of the support for the hstore ? operator Albe Laurenz <laurenz.albe@wien.gv.at>
  0 siblings, 1 reply; 5+ messages in thread

From: Thomas Kellerer @ 2015-11-18 07:44 UTC (permalink / raw)
  To: pgsql-jdbc

Hello,

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.

Regards
Thomas



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: State of the support for the hstore ? operator
  2015-11-18 07:44 State of the support for the hstore ? operator Thomas Kellerer <spam_eater@gmx.net>
@ 2015-11-18 10:35 ` Albe Laurenz <laurenz.albe@wien.gv.at>
  2015-11-18 10:53   ` Re: State of the support for the hstore ? operator Thomas Kellerer <spam_eater@gmx.net>
  2015-11-18 13:35   ` Re: State of the support for the hstore ? operator Albe Laurenz <laurenz.albe@wien.gv.at>
  0 siblings, 2 replies; 5+ messages in thread

From: Albe Laurenz @ 2015-11-18 10:35 UTC (permalink / raw)
  To: 'Thomas Kellerer *EXTERN*' <spam_eater@gmx.net>; 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



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc


^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: State of the support for the hstore ? operator
  2015-11-18 07:44 State of the support for the hstore ? operator Thomas Kellerer <spam_eater@gmx.net>
  2015-11-18 10:35 ` Re: State of the support for the hstore ? operator Albe Laurenz <laurenz.albe@wien.gv.at>
@ 2015-11-18 10:53   ` Thomas Kellerer <spam_eater@gmx.net>
  2015-11-18 13:10     ` Re: State of the support for the hstore ? operator Albe Laurenz <laurenz.albe@wien.gv.at>
  1 sibling, 1 reply; 5+ messages in thread

From: Thomas Kellerer @ 2015-11-18 10:53 UTC (permalink / raw)
  To: pgsql-jdbc

Albe Laurenz schrieb am 18.11.2015 um 11:35:
>> 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"
>>
> I looked into the source, and you can escape the question mark by doubling it.

Ah, right, thanks. 

I knew there was something available - I tried \? and "?" but didn't think of ??

Thomas



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: State of the support for the hstore ? operator
  2015-11-18 07:44 State of the support for the hstore ? operator Thomas Kellerer <spam_eater@gmx.net>
  2015-11-18 10:35 ` Re: State of the support for the hstore ? operator Albe Laurenz <laurenz.albe@wien.gv.at>
  2015-11-18 10:53   ` Re: State of the support for the hstore ? operator Thomas Kellerer <spam_eater@gmx.net>
@ 2015-11-18 13:10     ` Albe Laurenz <laurenz.albe@wien.gv.at>
  0 siblings, 0 replies; 5+ messages in thread

From: Albe Laurenz @ 2015-11-18 13:10 UTC (permalink / raw)
  To: 'Thomas Kellerer *EXTERN*' <spam_eater@gmx.net>; pgsql-jdbc

Thomas Kellerer wrote:
> Albe Laurenz schrieb am 18.11.2015 um 11:35:
>>> 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"
>>>
>> I looked into the source, and you can escape the question mark by doubling it.
> 
> Ah, right, thanks.
> 
> I knew there was something available - I tried \? and "?" but didn't think of ??

I see that it is mentioned in the documentation source (since Dec 2014, commit
31c5fcf9d620eb8403ec03682d8f90210da827f3), but I can't find it in the documentation
available on the web site.

Has the documentation on the web site been built recently?

I tried to build the documentation myself with "ant -lib lib doc", but it
failed with

java.io.FileNotFoundException: /path/to/pgjdbc/doc/${docbook.stylesheet} (No such file or directory)

Am I missing something?

Yours,
Laurenz Albe

-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc


^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: State of the support for the hstore ? operator
  2015-11-18 07:44 State of the support for the hstore ? operator Thomas Kellerer <spam_eater@gmx.net>
  2015-11-18 10:35 ` Re: State of the support for the hstore ? operator Albe Laurenz <laurenz.albe@wien.gv.at>
@ 2015-11-18 13:35   ` Albe Laurenz <laurenz.albe@wien.gv.at>
  1 sibling, 0 replies; 5+ messages in thread

From: Albe Laurenz @ 2015-11-18 13:35 UTC (permalink / raw)
  To: 'Albe Laurenz *EXTERN*' <laurenz.albe@wien.gv.at-extern>; 'Thomas Kellerer *EXTERN*' <spam_eater@gmx.net>; pgsql-jdbc

Laurenz Albe wrote:
> 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"

> 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.

Here:
https://github.com/pgjdbc/pgjdbc/pull/427

Yours,
Laurenz Albe

-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc


^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2015-11-18 13:35 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-11-18 07:44 State of the support for the hstore ? operator Thomas Kellerer <spam_eater@gmx.net>
2015-11-18 10:35 ` Albe Laurenz <laurenz.albe@wien.gv.at>
2015-11-18 10:53   ` Thomas Kellerer <spam_eater@gmx.net>
2015-11-18 13:10     ` Albe Laurenz <laurenz.albe@wien.gv.at>
2015-11-18 13:35   ` Albe Laurenz <laurenz.albe@wien.gv.at>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox