Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U62RR-0007pq-JF for pgsql-jdbc@arkaria.postgresql.org; Thu, 14 Feb 2013 17:17:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1U62RR-0000xA-0Z for pgsql-jdbc@arkaria.postgresql.org; Thu, 14 Feb 2013 17:17:49 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U62RQ-0000x4-EG for pgsql-jdbc@postgresql.org; Thu, 14 Feb 2013 17:17:48 +0000 Received: from outbound.vnet-inc.com ([216.146.104.103]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U62RJ-0005TV-6W for pgsql-jdbc@postgresql.org; Thu, 14 Feb 2013 17:17:47 +0000 Received: from [192.168.157.132] (unknown [76.75.27.41]) by outbound.vnet-inc.com (Postfix) with ESMTP id 6F98B5A87; Thu, 14 Feb 2013 10:17:39 -0700 (MST) Message-ID: <511D1BFA.4080303@ttc-cmc.net> Date: Thu, 14 Feb 2013 10:16:42 -0700 From: dmp User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.13) Gecko/20100914 SeaMonkey/2.0.8 MIME-Version: 1.0 To: Ladislav DANKO , pgsql-jdbc@postgresql.org Subject: Re: rounded brackets in prepared statement References: <511A926E.4080106@enaktyment.cz> <511AFB32.9080302@ttc-cmc.net> <511CA443.5020900@enaktyment.cz> In-Reply-To: <511CA443.5020900@enaktyment.cz> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org 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