Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YDLhS-0002Ov-Ik for pgsql-jdbc@arkaria.postgresql.org; Mon, 19 Jan 2015 23:25:38 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YDLhR-0003nV-VB for pgsql-jdbc@arkaria.postgresql.org; Mon, 19 Jan 2015 23:25:38 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YDLhR-0003nP-08 for pgsql-jdbc@postgresql.org; Mon, 19 Jan 2015 23:25:37 +0000 Received: from omr-m10.mx.aol.com ([64.12.143.86]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YDLhM-0002vh-5D for pgsql-jdbc@postgresql.org; Mon, 19 Jan 2015 23:25:34 +0000 Received: from mtaomg-aai02.mx.aol.com (mtaomg-aai02.mx.aol.com [172.27.2.100]) by omr-m10.mx.aol.com (Outbound Mail Relay) with ESMTP id 544A7704D375C; Mon, 19 Jan 2015 18:25:30 -0500 (EST) Received: from core-lpb03e.mail.aol.com (core-lpb03.mail.aol.com [10.76.10.13]) by mtaomg-aai02.mx.aol.com (OMAG/Core Interface) with ESMTP id CEA8938000086; Mon, 19 Jan 2015 18:25:29 -0500 (EST) Received: from 172.56.22.200 by webprd-a17.mail.aol.com (10.72.23.225) with HTTP (WebMailUI); 2015-Jan-19 23:25:29 Date: Mon, 19 Jan 2015 18:25:29 -0500 From: rapidtransit440@aol.com To: pgsql-jdbc@postgresql.org, peter.mortier@gmail.com Message-Id: <14b0483eb30-3b0b-8bf9@webprd-a17.mail.aol.com> In-Reply-To: References: Subject: Re: problem with pgjdbc prepared statements and new jsonb exists operator (?) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_41068_1450743762.1421709929263" X-MB-Message-Source: WebUI X-MB-Message-Type: User X-Mailer: JAS AolApp/2.2.6.4-Android 4.x X-Originating-IP: [172.56.22.200] x-aol-global-disposition: G DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mx.aol.com; s=20140625; t=1421709930; bh=2QqAlkDwwPpigkwS27CKDv/HPghdcxxhow882fw3k0o=; h=From:To:Subject:Message-Id:Date:MIME-Version:Content-Type; b=y4bo0TP+5Hy3V+hzKnmTiRkkwbL+wOJHgkyiO4i5xXtSinqR2cSDHoxBopUwBZAyo ImNB4rxX+w5nwqXrnmqJZR0H5BJjRqIILeebcmYBC8rqlVtdiB7ckLyuoDbVQlc0Us BX3wpQJk0VyWqIZA6IM5sGGO3c52ddTEiKTh4EZQ= x-aol-sid: 3039ac1b026454bd926941a7 X-Pg-Spam-Score: -1.7 (-) 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 ------=_Part_41068_1450743762.1421709929263 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit As a temporary work maybe try introducing a new operator. JSONB stuff is fairly new and the development team has to make absolutely sure any changes will not break customers applications I think they have paid support customers for versions going back to version 7 Sent from AOL Mobile Mail On Monday, January 19, 2015 Peter Mortier wrote: Hello, I'm testing out the new jsonb functionality in Postgresql 9.4 and ran across an issue with some of the newly introduced operators for the jsonb datatype described here ( http://www.postgresql.org/docs/9.4/static/functions-json.html#FUNCTIONS-JSONB-OP-TABLE) when used with JDBC prepared statements. I have created the following table: create table "JsonTest0" ("id" BIGSERIAL NOT NULL PRIMARY KEY,"json" jsonb DEFAULT ' {"a":"v1","b":2} ' NOT NULL) When I'm creating and executing a simple statement using the exist operator then I get expected results back: connection.createStatement.executeQuery("select x2.\"json\" from \"JsonTest0\" x2 where (x2.\"json\" ? 'c') = true") When I try to execute the same query using a prepared statement, I get the following: connection.prepareStatement("select x2.\"json\" from \"JsonTest0\" x2 where (x2.\"json\" ? 'c') = true").executeQuery() org.postgresql.util.PSQLException: No value specified for parameter 1. at org.postgresql.core.v3.SimpleParameterList.checkAllParametersSet(SimpleParameterList.java:216) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:244) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:560) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302) So it looks like the ? character, which is used as the jsonb exists operator is confusing the prepared statement parser, which treats it as a parameter substitution instead. Is this expected behaviour and am I stuck with non-prepared statements when using the new ?, ?& and ?| jsonb operators ? Any other workarounds, like escaping or function aliases that you may know of ? I tested with both: 9.3-1100-jdbc41 and 9.4-1200-jdbc41-SNAPSHOT versions BR, Peter Mortier ------=_Part_41068_1450743762.1421709929263 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit

As a temporary work maybe try introducing a new operator. JSONB stuff is fairly new and the development team has to make absolutely sure any changes will not break customers applications I think they have paid support customers for versions going back to version 7



Sent from AOL Mobile Mail




On Monday, January 19, 2015 Peter Mortier <peter.mortier@gmail.com> wrote:

Hello,

I'm testing out the new jsonb functionality in Postgresql 9.4 and ran across an issue with some of the newly introduced operators for the jsonb datatype described here ( http://www.postgresql.org/docs/9.4/static/functions-json.html#FUNCTIONS-JSONB-OP-TABLE) when used with JDBC prepared statements.

I have created the following table:

create table "JsonTest0" ("id" BIGSERIAL NOT NULL PRIMARY KEY,"json" jsonb DEFAULT ' {"a":"v1","b":2} ' NOT NULL)

When I'm creating and executing a simple statement using the exist operator then I get expected results back:

connection.createStatement.executeQuery("select x2.\"json\" from \"JsonTest0\" x2 where (x2.\"json\" ? 'c') = true")

When I try to execute the same query using a prepared statement, I get the following:

connection.prepareStatement("select x2.\"json\" from \"JsonTest0\" x2 where (x2.\"json\" ? 'c') = true").executeQuery()

org.postgresql.util.PSQLException: No value specified for parameter 1.
at org.postgresql.core.v3.SimpleParameterList.checkAllParametersSet(SimpleParameterList.java:216)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:244)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:560)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)

So it looks like the ? character, which is used as the jsonb exists operator is confusing the prepared statement parser, which treats it as a parameter substitution instead.

Is this expected behaviour and am I stuck with non-prepared statements when using the new ?, ?& and ?| jsonb operators ?
Any other workarounds, like escaping or function aliases that you may know of ?

I tested with both: 9.3-1100-jdbc41 and 9.4-1200-jdbc41-SNAPSHOT versions

BR,

Peter Mortier







------=_Part_41068_1450743762.1421709929263--