Re: PQunescapebytea not reverse of PQescapebytea? - Mailing list pgsql-general

From Tom Lane
Subject Re: PQunescapebytea not reverse of PQescapebytea?
Date
Msg-id 15482.1393730391@sss.pgh.pa.us
Whole thread Raw
In response to PQunescapebytea not reverse of PQescapebytea?  (Karthik Segpi <karthik.segpi@gmail.com>)
List pgsql-general
Karthik Segpi <karthik.segpi@gmail.com> writes:
> I have a 'bytea' column in the database, onto which my custom C application
> is inserting encrypted data. Before inserting, I am calling
> 'PQescapebytea()' to escape the ciphertext. However, after SELECT, the data
> needs to be 'un-escaped' before attempting to decrypt. I am trying to
> 'un-escape' using 'PQunescapebytea'. However, I am finding that
> 'PQunescapebytea' is not  exact inverse of 'PQescapebytea'.

It's not supposed to be, as the fine manual points out:

    This conversion is not exactly the inverse of PQescapeBytea, because the
    string is not expected to be "escaped" when received from PQgetvalue. In
    particular this means there is no need for string quoting considerations,
    and so no need for a PGconn parameter.

If you're having problems, it's probably because you are misusing one
function or the other.  A likely bet is that you're passing the output
of PQescapeBytea through some additional processing rather than just
sticking it into an INSERT statement with single quotes around it.
But it's impossible to be sure without seeing a detailed example of
what you're doing, on both the insertion and extraction sides.

            regards, tom lane


pgsql-general by date:

Previous
From: Steve Atkins
Date:
Subject: Re: Replacing Ordinal Suffixes
Next
From: "George Weaver"
Date:
Subject: Re: Replacing Ordinal Suffixes