From: | Joe Conway <mail(at)joeconway(dot)com> |
---|---|
To: | Iker Arizmendi <iker(at)research(dot)att(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: PQunescapeBytea |
Date: | 2004-02-11 01:09:45 |
Message-ID: | 402980D9.8070505@joeconway.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Iker Arizmendi wrote:
> Am I using the escape/unescape functions incorrectly? I was
> expecting the unescape function to produce an exact
> duplicate of a[].
The two functions are not, and should not be, precise reciprocals.
PQescapeBytea() prepares a string to be used in an SQL statement,
meaning it must produce something in the form "\\ooo" (without the
quotes) -- notice *two* backslashes before the octal number. This is
needed because the SQL string literal parser eats one backslash, and the
byteain() function needs the other to recognize that it is receiving an
octal sequence.
PQunescapeBytea(), on the other hand, takes a string in the form "\ooo"
which is the output format produced by byteaout() function. Notice that
only *one* backslash is expected before the octal.
In your example, "aaaa\0" is fed into PQescapeBytea(), producing
"aaaa\\000". When that is fed into PQunescapeBytea(), the two
backslashes are seen as a single backslash that has been escaped.
Therefore the two backslashes are transformed into a single unescaped
backslash, and the octal number is taken as a literal part of the
string, producing "aaaa\000".
HTH,
Joe
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2004-02-11 04:02:08 | Re: Changing schema owner? |
Previous Message | Jenny Zhang | 2004-02-11 00:54:47 | Re: DB cache size strategies |