Re: PQescapeByteaConn - returns wrong string for PG9.1 Beta3

From: Florian Pflug <fgp(at)phlo(dot)org>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Petro Meier <petro85(at)gmx(dot)de>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQescapeByteaConn - returns wrong string for PG9.1 Beta3
Date: 2011-07-27 19:44:06
Message-ID: F3FDB41A-4352-4367-B905-0BB4546CB7E1@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Jul27, 2011, at 20:05 , Alvaro Herrera wrote:
> Excerpts from Petro Meier's message of mié jul 27 02:51:22 -0400 2011:
>
>> If I use PQescapeByteaConn() for a conenction to a PG9.1 Beta3 server,
>> this function returns (e.g.) "\xea2abd8ef31...(and so on.)...".
>>
>> Here the problem: there should be a second backslash in the prefix.
>> The SQL Statement which uses this string (INSERT statement in my case)
>> returns with an error ("Invalid byte sequence..."). If I add the second
>> backslash manually everything works fine.
>
> You're just being bitten by the fact that the
> standard_conforming_strings setting changed its default from false to
> true. If you want the old behavior, you can just flip the switch, but
> the recommended action is to change your expectations. You can use E''
> if you want backslashes to continue working without changing the switch.

Hm, but PQescapeByteaConn() shouldn't produce a literal that the server
later rejects, no matter what standard_conforming_strings is set to.

It looks like PQescapeByteaConn() does the right thing here, though -
it doesn't escape the backslash in it's result when dealing with 9.1,
presumably because that server has wstandard_conforming_strings set to on.
But why then is the server rejecting the result?

The only way I can see that make that happend would be to prefix the
string returned by PQescapeByteaConn() with 'E'.

@OP: Could you post the code fragment that causes the error?

best regards,
Florian Pflug

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2011-07-27 19:55:25 Re: Check constraints on partition parents only?
Previous Message Tom Lane 2011-07-27 19:43:35 Re: PQescapeByteaConn - returns wrong string for PG9.1 Beta3