pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: dmp <danap@ttc-cmc.net>
To: Ladislav DANKO <ladislav.danko@enaktyment.cz>
To: pgsql-jdbc@postgresql.org
Subject: Re: rounded brackets in prepared statement
Date: Thu, 14 Feb 2013 10:16:42 -0700
Message-ID: <511D1BFA.4080303@ttc-cmc.net> (raw)
In-Reply-To: <511CA443.5020900@enaktyment.cz>
References: <511A926E.4080106@enaktyment.cz>
	<511AFB32.9080302@ttc-cmc.net>
	<511CA443.5020900@enaktyment.cz>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

Hello laco,

I would read futher in the documentation, but a little experiementing
will results.

Given column content: 'the(ishere'

col LIKE '%(%' (OK)
col='the(ishere' (OK)
col~'the(ishere' (FAILS)

So:

(=) - matches exact string input
(LIKE) - same as equal, but can use wild card character, etc, ie %
(~) - Throws the PQLException: Error: invalid regular expression:
       parentheses () not balanced

It not a matter of escaping. Certain operators, {=, LIKE, ?, ?, ... }
use the given input string of characters and do matching directly
without using Regular Expession Patterns looks like. Where as
{~, ?, ?, ... } interepret the input as being a Regular Expression
Pattern.

danap.

Ladislav DANKO wrote:
> so JDBC driver is detecting matching type and if there's "=" (equal)
> then it's
> doing escaping and if there is "~" (regular expression pattern) the i
> need to do
> escaping by hand?
>
> laco
>
>
>
> On 13.2.2013 3:32, dmp wrote:
>> It appears that since the argument to your prepare statement is a WHERE
>> operation and you are using the ~, Match Regular Expression Case
>> Sensitive, operator then the input is deemed as such. So parenthesis
>> are valid constructs in these cases.
>>
>> Example from Documentation: POSIX Regular Expression Patterns
>> Chapter 9. Functions & Operators
>>
>> 'abc' ~ '(b|d)' true
>> 'abc' ~ '(^(b|c)' false
>>
>> danap.
>>
>> Ladislav DANKO wrote:
>>> Hi folks,
>>>
>>> my setup: Java 1.6, JDBC PostgreSQL JDBC4 driver 9.1-903.
>>>
>>> Why when I do:
>>>
>>> PreparedStatement ps = myConnection.prepareStatement("SELECT a,b,c FROM
>>> mytable WHERE category ~ ?");
>>> ps.setString(1, "my/super/category/a(bcdef");
>>> result = ps.executeQuery();
>>>
>>> I need to escape rounded bracket in setString in this way:
>>> ps.setString(1, "super/category/a(bcdef".replaceAll("\\(", "\\\\(")));
>>>
>>> I think it has somethink to do with regular expessions but ot know much
>>> more about it.
>>>
>>> --
>>> With kind regards,
>>>
>>> Ladislav DANKO



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



view thread (4+ messages)

Message-ID: <511D1BFA.4080303@ttc-cmc.net>
Permalink:  ../511D1BFA.4080303@ttc-cmc.net/
Also on:    postgresql.org/message-id/511D1BFA.4080303@ttc-cmc.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: danap@ttc-cmc.net, ladislav.danko@enaktyment.cz
  Subject: Re: rounded brackets in prepared statement
  In-Reply-To: <511D1BFA.4080303@ttc-cmc.net>
  References: <511A926E.4080106@enaktyment.cz> <511AFB32.9080302@ttc-cmc.net> <511CA443.5020900@enaktyment.cz> <511D1BFA.4080303@ttc-cmc.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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