Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id CF0D31337B6E for ; Wed, 2 Feb 2011 17:26:22 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 59574-02 for ; Wed, 2 Feb 2011 21:26:16 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from momjian.us (momjian.us [70.90.9.53]) by mail.postgresql.org (Postfix) with ESMTP id E264D1337B68 for ; Wed, 2 Feb 2011 17:26:14 -0400 (AST) Received: (from bruce@localhost) by momjian.us (8.11.6/8.11.6) id p12LPqd03573; Wed, 2 Feb 2011 16:25:52 -0500 (EST) From: Bruce Momjian Message-Id: <201102022125.p12LPqd03573@momjian.us> Subject: Re: [GENERAL] Gripe: bytea_output default => data corruption To: ljb Date: Wed, 2 Feb 2011 16:25:52 -0500 (EST) CC: pgsql-docs@postgresql.org X-Mailer: ELM [version 2.4ME+ PL124 (25)] MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ELM1296681952-7025-1_" Content-Transfer-Encoding: 7bit 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: 201102/5 X-Sequence-Number: 6353 --ELM1296681952-7025-1_ Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="US-ASCII" ljb wrote: > tgl@sss.pgh.pa.us wrote: > > I think we should simply remove the description of *how* the escaping is > > performed, and state only that the function produces a suitably escaped > > literal string. Anything else is not future-proof, and could someday > > break the way this wording did. > > Perhaps it would be best to remove escaping details here. But the > description of PQescapeBytea() might need to be rewritten, too. Without > describing exactly what PQescapeByteaConn() does, it is hard to understand > what PQescapeBytea() does not do, and why it therefore "might give the > wrong results". > > I think the actual function behavior should be documented somewhere. Even > though it might change again. Based on this report, I have created the attached documentation patch which clarifies the libpq behavior for escaping bytea. I am planning to backpatch this to 9.0 as well. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. + --ELM1296681952-7025-1_ Content-Transfer-Encoding: 7bit Content-Type: text/x-diff Content-Disposition: inline; filename="/rtmp/libpq.diff" diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index 7b70970..26f5140 100644 *** a/doc/src/sgml/libpq.sgml --- b/doc/src/sgml/libpq.sgml *************** unsigned char *PQescapeByteaConn(PGconn *** 3419,3434 **** ! Certain byte values must be escaped (but all ! byte values can be escaped) when used as part ! of a bytea literal in an SQL ! statement. In general, to escape a byte, it is converted into the ! three digit octal number equal to the octet value, and preceded by ! usually two backslashes. The single quote (') and backslash ! (\) characters have special alternative escape ! sequences. See for more ! information. PQescapeByteaConn performs this ! operation, escaping only the minimally required bytes. --- 3419,3429 ---- ! Certain byte values must be escaped when used as part of a ! bytea literal in an SQL statement. ! PQescapeByteaConn escapes such bytes using ! either hex encoding or backslash escaping. See for more information. *************** unsigned char *PQescapeBytea(const unsig *** 3486,3495 **** The only difference from PQescapeByteaConn is that PQescapeBytea does not take a PGconn parameter. Because of this, it cannot adjust its behavior ! depending on the connection properties (in particular, whether ! standard-conforming strings are enabled) and therefore ! it might give the wrong results. Also, it has no ! way to return an error message on failure. --- 3481,3490 ---- The only difference from PQescapeByteaConn is that PQescapeBytea does not take a PGconn parameter. Because of this, it cannot adjust its behavior ! depending on the connection properties (e.g. ! standard_conforming_strings, bytea_output) ! and therefore might give the wrong results. Also, ! it has no way to return an error message on failure. diff --git a/doc/src/sgml/release-9.0.sgml b/doc/src/sgml/release-9.0.sgml index 2288f1b..c43f142 100644 *** a/doc/src/sgml/release-9.0.sgml --- b/doc/src/sgml/release-9.0.sgml *************** *** 2342,2348 **** whether hex or traditional format is used for bytea output. Libpq's PQescapeByteaConn() function automatically uses the hex format when connected to PostgreSQL 9.0 ! or newer servers. --- 2342,2349 ---- whether hex or traditional format is used for bytea output. Libpq's PQescapeByteaConn() function automatically uses the hex format when connected to PostgreSQL 9.0 ! or newer servers. However, pre-9.0 libpq versions will not ! correctly process hex format from newer servers. --ELM1296681952-7025-1_ Content-Transfer-Encoding: 7bit Content-Type: text/x-diff Content-Disposition: inline; filename="/rtmp/libpq.diff" diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index 7b70970..26f5140 100644 *** a/doc/src/sgml/libpq.sgml --- b/doc/src/sgml/libpq.sgml *************** unsigned char *PQescapeByteaConn(PGconn *** 3419,3434 **** ! Certain byte values must be escaped (but all ! byte values can be escaped) when used as part ! of a bytea literal in an SQL ! statement. In general, to escape a byte, it is converted into the ! three digit octal number equal to the octet value, and preceded by ! usually two backslashes. The single quote (') and backslash ! (\) characters have special alternative escape ! sequences. See for more ! information. PQescapeByteaConn performs this ! operation, escaping only the minimally required bytes. --- 3419,3429 ---- ! Certain byte values must be escaped when used as part of a ! bytea literal in an SQL statement. ! PQescapeByteaConn escapes such bytes using ! either hex encoding or backslash escaping. See for more information. *************** unsigned char *PQescapeBytea(const unsig *** 3486,3495 **** The only difference from PQescapeByteaConn is that PQescapeBytea does not take a PGconn parameter. Because of this, it cannot adjust its behavior ! depending on the connection properties (in particular, whether ! standard-conforming strings are enabled) and therefore ! it might give the wrong results. Also, it has no ! way to return an error message on failure. --- 3481,3490 ---- The only difference from PQescapeByteaConn is that PQescapeBytea does not take a PGconn parameter. Because of this, it cannot adjust its behavior ! depending on the connection properties (e.g. ! standard_conforming_strings, bytea_output) ! and therefore might give the wrong results. Also, ! it has no way to return an error message on failure. --ELM1296681952-7025-1_--