Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 6F12D1337B85 for ; Thu, 25 Nov 2010 13:23:12 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 65427-07; Thu, 25 Nov 2010 17:23:05 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id CB1D71337B53; Thu, 25 Nov 2010 13:23:04 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id oAPHN3ow014934; Thu, 25 Nov 2010 12:23:03 -0500 (EST) To: Maciek Sakrejda cc: =?UTF-8?Q?Rados=C5=82aw_Smogura?= , PG Hackers , PostgreSQL JDBC List Subject: Re: [JDBC] JDBC and Binary protocol error, for some statements In-reply-to: References: <201011241918.40930.rsmogura@softperience.eu> Comments: In-reply-to Maciek Sakrejda message dated "Wed, 24 Nov 2010 23:25:14 -0800" Date: Thu, 25 Nov 2010 12:23:03 -0500 Message-ID: <14932.1290705783@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201011/1734 X-Sequence-Number: 174877 Maciek Sakrejda writes: > Since triggering the set of FEBE messages that leads to this was tied > deep into the guts of JDBC, I opted for raw wire protocol. It looks > like the following sequence of messages from the client leads to this > result format mixup: > 1. Parse, with statement name "S_1", sql "SELECT $1::int", and > parameter type oid 0 (ask server to guess) > 2. Describe "S_1" > 3. Bind "S_1" to anonymous portal, with param formats [ 0 (text) ], > param values [ '2' ], result formats [ 1 (binary) ] > 4. Execute anonymous portal (returning all rows) > 5. Sync > I have not tried to narrow this further yet. This essentially > reproduces what Radosław was seeing but outside of the JDBC driver. > That is, the server responds with: > 1. Parse completion > 2. Parameter description, with type oids [ 23 ] > 3. Row description, with empty table data, type oids [ 23 ], type > length 4, type mod -1, and format 0 (text) > 4. Bind completion > 5. DataRow, with the result in binary, as requested, but not as > described in message (3) above > 6. Command completion & RFQ AFAICS this isn't a bug. What you're issuing Describe against is the prepared statement, not the portal. The result column formats are not specified by a prepared statement, so Describe just returns zeroes for them. Result column formats are specified by the Bind command, which creates a Portal. If you'd issued the Describe against the Portal, you should get back the correct format codes. Per the protocol specification: The Describe message (statement variant) specifies the name of an existing prepared statement (or an empty string for the unnamed prepared statement). The response is a ParameterDescription message describing the parameters needed by the statement, followed by a RowDescription message describing the rows that will be returned when the statement is eventually executed (or a NoData message if the statement will not return rows). ErrorResponse is issued if there is no such prepared statement. Note that since Bind has not yet been issued, the formats to be used for returned columns are not yet known to the backend; the format code fields in the RowDescription message will be zeroes in this case. Now, if there's something in the JDBC driver that expects DescribeStatement to return useful result format codes, that'd be a bug in the driver. regards, tom lane