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

Поиск
Список
Период
Сортировка
От Paul Buder
Тема I was wrong about Re: copy works, \copy doesn't (fwd)
Дата
Msg-id Pine.LNX.4.44.0211091515310.29853-100000@shell1.aracnet.com
обсуждение исходный текст
Список 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
work.

# double up the escape character twice! Once for the 'copy from' command and
# once for postgres bytea type escaping.
$text=~s/\\/\\\\\\\\/g;
$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 по дате отправления:

Предыдущее
От: Paul Buder
Дата:
Сообщение: copy works, \copy doesn't
Следующее
От: pgsql-bugs@postgresql.org
Дата:
Сообщение: Bug #812: can not compile 7.3b5 on Suse8.1 with perl