From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
---|---|
To: | Gregg Jaskiewicz <gryzman(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: bytea insert difference between 8.3 and 9.x |
Date: | 2011-09-26 13:39:53 |
Message-ID: | CAHyXU0w+rSUZFxmnrLyANMZqqm7UhLf4L0j85BV0r96HX3BCVg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Mon, Sep 26, 2011 at 5:51 AM, Gregg Jaskiewicz <gryzman(at)gmail(dot)com> wrote:
> So consider this code C++, using libpqxx:
>
> string = "INSERT INTO foo(x) VALUES( E'" + T.esc_raw(data) + "' )";
>
> foo(x) is bytea , before you ask.
>
> On 8.3, it works fine.
> On 9.x:
>
> ERROR: invalid byte sequence for encoding "UTF8": 0x00 (if \000 is in
> the string).
>
> Now, I can take out the E'' and it will work fine on 9.X, but will
> whine about it on 8.3. (HINT: Use the escape string syntax for
> escapes, e.g., E'\r\n'.)
>
>
> I need one piece of code that will work on both, what should I do in
> this case ?
urk -- I have to be honest -- that's a pretty lousy way to send bytea.
Personally, I'd encode the string as hex and send it like this:
"INSERT INTO foo(x) VALUES( decode('" + hex_string + "'))";
libpqxx doesn't have the ability to parameterize queries?
merlin
From | Date | Subject | |
---|---|---|---|
Next Message | Gregg Jaskiewicz | 2011-09-26 13:50:58 | Re: bytea insert difference between 8.3 and 9.x |
Previous Message | Albe Laurenz | 2011-09-26 13:32:20 | Re: changing from postgreSQL 8.3 to 9.0 |