> Oops, you're right.  I've fixed this in revision [1265].  Thanks for a
> thorough report.

Thanks! However, an issue remains.

In this case I am writing to a table with one column being a bytea
(rather than a varchar). The r1265 change unfortunately does not solve
the problem, since there seem to be two levels of unescaping involved.

Looking at the output of pg_dump, binary values have their backslash
escaped aswell (so \\000 instead of \000). I will admit that I find
the PostgreSQL's escaping to be quite strange and I never understood
why there is not simply a single escaping scheme regardless of
binary/non-binary data. In this particular case I suppose one level of
unescaping is being applied by the COPY receiver, and the second level
further into the backend where newlines and such need not be escaped,
but binary data does.

In order to make the table writer work in the case of inserting binary
data into a byteaa column I had to further make this modification:

-      R += '\\';
+      R += "\\\\";

Note that one specifically should not do this in the escaped character
case (i.e., newlines are \n, not \\n), which is consistent with the
above mentioned theory on escaping.

This solves the problem in the case of inserting binary data into a
bytea column, and still seems to work in the case of varchar:s (i.e.,
\000 is inserted into the cell without truncation or errors). That
said, I am not prepared to claim that I am sure it will not have any
adverse effects on non-bytea columns. Someone more intricately
familiar with the PostgreSQL escaping situation can perhaps
confirm/deny.

I can provide a proper patch if you wish, but I suspect it's easier to
just edit the source than to apply the a one-liner patch anyway. (I
happen to be some hoop jumping away from getting a patch against
r1265).

-- 
/ Peter Schuller

PGP userID: 0xE9758B7D or 'Peter Schuller <[EMAIL PROTECTED]>'
Key retrieval: Send an E-Mail to [EMAIL PROTECTED]
E-Mail: [EMAIL PROTECTED] Web: http://www.scode.org

Attachment: pgpD5fsOcc4Wt.pgp
Description: PGP signature

_______________________________________________
Libpqxx-general mailing list
[email protected]
http://gborg.postgresql.org/mailman/listinfo/libpqxx-general

Reply via email to