Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1be0xt-0006KN-OF for pgsql-jdbc@arkaria.postgresql.org; Sun, 28 Aug 2016 14:21:37 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1be0xs-0001BY-Ra for pgsql-jdbc@arkaria.postgresql.org; Sun, 28 Aug 2016 14:21:36 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1be0xO-0000cX-8o for pgsql-jdbc@postgresql.org; Sun, 28 Aug 2016 14:21:06 +0000 Received: from mail-pf0-x230.google.com ([2607:f8b0:400e:c00::230]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1be0xL-0002UH-1X for pgsql-jdbc@postgresql.org; Sun, 28 Aug 2016 14:21:04 +0000 Received: by mail-pf0-x230.google.com with SMTP id p64so43212442pfb.1 for ; Sun, 28 Aug 2016 07:21:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=labkey-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to; bh=uikOPwts64lCiXZy5y9YjC5VAsaxEfndiiDJBX5kHeM=; b=zdfmiVxGSb0+j84OWmlIqylHGcXs/43yBRjVd/CvvjGjYLhjvAfyDH7VVu+Ox8fpuy CmuLxaf5/0K9+LftfCEmrHcsrPH/EsGj3GiIA2WDM36BwLsvNCbwmPAJXkAN7FULdboU lXMh5nZo8x0Vds36WKN0GprGjFBVirbf4PzIjW/ASMzo22e7OEeDbofJ0fMJ+1MnK15E MRdIgamPvBqVgwkxXRR8hOiMYkLbDAzwsYrx6yltlxANHqx2sHACxkj6ceI9/qLNETLg IrDdmUDDg//eH2qSJxO32Dtn7KTuwuDXOQisJorn98AZSrLNRpsv0mH8KizzPE37kUWG Gprg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to; bh=uikOPwts64lCiXZy5y9YjC5VAsaxEfndiiDJBX5kHeM=; b=chRP9zl0MtTH3ePYMpGdoCqY+3eYRnPlMulMJA3pM4lvzEBYGOYSTfBU5Vos65tLfl PVBhZE1XXY3+NU6Oamg9/WEh3yppswXEemM2xuYmzLA8A/Ua86OeU23rf24Qytk46Vgq c8pVoQjx8JFeLAkA70Y4aX2c14ONyKXsQqyOUz9m6Qrh/lFTrXGV/nVeqQNm8vZUyA1h fJXKYqV9LdBucUvGecCkVlSzN5tbB/6mGx1N0igkYeyAyW2bxe8rKxYOFEUuUtLatcwk s4L2yXCfQ2DjN/N7ubINVNAfcQ7Rt45WJE9aK95Ufso/yF5Ru0p/001zz9IbZiuCksNa mjVw== X-Gm-Message-State: AE9vXwORsWmwAWH/TS6ulLtNRNFDeRa8djHAgF5MgIRsXEdtnEpmpSpgpPtZu7JsuKQjgw== X-Received: by 10.98.7.80 with SMTP id b77mr23643514pfd.136.1472394061477; Sun, 28 Aug 2016 07:21:01 -0700 (PDT) Received: from [192.168.1.136] ([24.19.58.248]) by smtp.googlemail.com with ESMTPSA id ty6sm42384687pac.18.2016.08.28.07.21.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Aug 2016 07:21:00 -0700 (PDT) Subject: Re: Simple queries with JDBC escaped scalar functions result in exceptions To: Andreas Joseph Krogh , Dave Cramer References: Cc: "pgsql-jdbc@postgresql.org" From: Adam Rauch Message-ID: Date: Sun, 28 Aug 2016 07:20:56 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------EEB694D63E0309001B03C8B7" X-Pg-Spam-Score: -2.6 (--) 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 This is a multi-part message in MIME format. --------------EEB694D63E0309001B03C8B7 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit In our development and test environments (but not production), our SQL generation engine inserts comments at strategic places in the queries it constructs, e.g., tagging a GUID with the real-world name of the object it represents or providing details about the requests from higher layers in the system that caused the query to be produced. When a query results in an exception, incorrect results, or poor performance, those comments help us better understand the query so we can fix or optimize it. Of course, this is legal and has been supported by the driver for many years. The dollar sign ($) is the only case we came across in our test environments, but it looks like a single quote (') or double quote (") in a comment also trips up the parser. As do the two-character combinations {D, {E, {F, {O, and {T... and their lowercase equivalents. A full set of test queries that fail when executed via postgresql-9.4.1209.jar: SELECT /* " */ {fn curdate()}; SELECT /* $ */ {fn curdate()}; SELECT /* ' */ {fn curdate()}; SELECT /* {D */ {fn curdate()}; SELECT /* {E */ {fn curdate()}; SELECT /* {F */ {fn curdate()}; SELECT /* {O */ {fn curdate()}; SELECT /* {T */ {fn curdate()}; SELECT /* {d */ {fn curdate()}; SELECT /* {e */ {fn curdate()}; SELECT /* {f */ {fn curdate()}; SELECT /* {o */ {fn curdate()}; SELECT /* {t */ {fn curdate()}; Thanks, Adam On 8/28/2016 6:43 AM, Andreas Joseph Krogh wrote: > På søndag 28. august 2016 kl. 03:18:42, skrev Dave Cramer > >: > > Looks like the JDBC mini parser is having troubles with that. Why > do you have comments in your sql ? > > I think the universial answer here is "Because you can". Many use > comments in SQL as a way to both understand what's going on better > (ie. when the SQL is generated by code) and to make logging easier. > There's no reason why a driver should not cope with valid comments. > --------------EEB694D63E0309001B03C8B7 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

In our development and test environments (but not production), our SQL generation engine inserts comments at strategic places in the queries it constructs, e.g., tagging a GUID with the real-world name of the object it represents or providing details about the requests from higher layers in the system that caused the query to be produced. When a query results in an exception, incorrect results, or poor performance, those comments help us better understand the query so we can fix or optimize it. Of course, this is legal and has been supported by the driver for many years.

The dollar sign ($) is the only case we came across in our test environments, but it looks like a single quote (') or double quote (") in a comment also trips up the parser. As do the two-character combinations {D, {E, {F, {O, and {T... and their lowercase equivalents. A full set of test queries that fail when executed via postgresql-9.4.1209.jar:

SELECT /* " */ {fn curdate()};
SELECT /* $ */ {fn curdate()};
SELECT /* ' */ {fn curdate()};
SELECT /* {D */ {fn curdate()};
SELECT /* {E */ {fn curdate()};
SELECT /* {F */ {fn curdate()};
SELECT /* {O */ {fn curdate()};
SELECT /* {T */ {fn curdate()};
SELECT /* {d */ {fn curdate()};
SELECT /* {e */ {fn curdate()};
SELECT /* {f */ {fn curdate()};
SELECT /* {o */ {fn curdate()};
SELECT /* {t */ {fn curdate()};

Thanks,
Adam

On 8/28/2016 6:43 AM, Andreas Joseph Krogh wrote:
På søndag 28. august 2016 kl. 03:18:42, skrev Dave Cramer <pg@fastcrypt.com>:
Looks like the JDBC mini parser is having troubles with that. Why do you have comments in your sql ? 
 
I think the universial answer here is "Because you can". Many use comments in SQL as a way to both understand what's going on better (ie. when the SQL is generated by code) and to make logging easier. There's no reason why a driver should not cope with valid comments.
 


--------------EEB694D63E0309001B03C8B7--