COPY FROM with BYTEA fields - escaping doesn't work

From: Toby Corkindale <toby(dot)corkindale(at)strategicdata(dot)com(dot)au>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: COPY FROM with BYTEA fields - escaping doesn't work
Date: 2012-10-04 02:58:39
Message-ID: 506CFB5F.4020602@strategicdata.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,
I'm trying to use the COPY .. FROM system with some data which includes
binary values. They aren't large, but they include invalid UTF8 bytes,
so I'm storing them into a BYTEA field.

However I get errors when I try to do this..

CREATE TABLE foo (id SERIAL PRIMARY KEY, bar BYTEA);
COPY foo (bar) FROM STDIN;
Test\xff\x0\x9Again
\.

The error given is:
ERROR: invalid byte sequence for encoding "UTF8": 0xff
CONTEXT: COPY foo, line 1: "Test\xff\x0\x9Again"

As far as I can tell, I'm obeying the instructions about escaping here:
http://www.postgresql.org/docs/current/static/sql-copy.html

I'm on version 9.1.5 of PostgreSQL.

Thanks,
Toby

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2012-10-04 03:15:17 Re: [PL/PGSQL] column name substitution in PG8.4
Previous Message Chris Travers 2012-10-04 02:08:01 Re: Fwd: pros and cons of two security models