Skip site navigation (1) Skip section navigation (2)

I was wrong about Re: copy works, \copy doesn't (fwd)

From: Paul Buder <paulb(at)aracnet(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: I was wrong about Re: copy works, \copy doesn't (fwd)
Date: 2002-11-09 23:16:09
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-bugs
I wrote:
> It seems the psql \copy command doesn't work properly when dealing
> with certain non-ascii characters (which ones I don't know).  At any rate
> I took some binary data and escaped it like so with perl.

I was wrong.  I wasn't escaping things properly; in particular,
ascii 0 needed to be escaped to \\000 .  Also I was using 'text' type
instead of 'bytea' type.  I thought 'copy' was working but it was
actually cutting off my input at the first ascii zero, whereas \copy
gave me the error message.  Sorry to waste people's time.

In the event anyone else is out there who wants to use binary data
with 'copy from' and is using perl to do the escaping this seems to

# double up the escape character twice! Once for the 'copy from' command and
# once for postgres bytea type escaping.
$text=~s/\n/\\\n/g;         # escape \n
$text=~s/\t/\\\t/g;         # escape \t
$text=~s/'/\\'/g;           # escape '
$text=~s/\x00/\\\\000/g;    # escape ascii 0

pgsql-bugs by date

Next:From: pgsql-bugsDate: 2002-11-10 22:43:53
Subject: Bug #812: can not compile 7.3b5 on Suse8.1 with perl
Previous:From: Paul BuderDate: 2002-11-09 19:30:52
Subject: copy works, \copy doesn't

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group