Re: How to insert zeros into a bytea column?

From: Joe Conway <mail(at)joeconway(dot)com>
To: Iklódi Lajos <il(at)mithrandir(dot)hu>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: How to insert zeros into a bytea column?
Date: 2002-02-23 21:04:07
Message-ID: 3C7803C7.4090207@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Iklódi Lajos wrote:
> Hello,
>
> I'm inserting data into a bytea colunm which can contain zero bytes. It
> seems that insertion stops at first zero:
>
> gkk=# CREATE TABLE test (id int4, adat bytea);
> CREATE
> gkk=# insert into test (id, adat) values (1, '\100\200\000\100\200');
> INSERT 164175 1
> gkk=# select * from test;
> id | adat
> ----+-------
> 1 | @\200
> (1 row)

You should double up on the backslashes:

test=# CREATE TABLE test (id int4, adat bytea);
CREATE
test=# insert into test (id, adat) values (1, '\\100\\200\\000\\100\\200');
INSERT 82097 1
test=# select * from test;
id | adat
----+----------------
1 | @\200\000(at)\200
(1 row)

See for more info:
http://www.us.postgresql.org/users-lounge/docs/7.2/postgres/datatype-binary.html

HTH,
Joe

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Christopher Sawtell 2002-02-23 21:32:12 Re: should I use postgresql arrays...
Previous Message Benoit Menendez 2002-02-23 20:20:08 More open source database comparison...