pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedHow to insert zeros into a bytea column?
2+ messages / 2 participants
[nested] [flat]
* How to insert zeros into a bytea column?
@ 2002-02-23 20:16 Iklódi Lajos <il@mithrandir.hu>
0 siblings, 1 reply; 2+ messages in thread
From: Iklódi Lajos @ 2002-02-23 20:16 UTC (permalink / raw)
To: pgsql-sql
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)
gkk=# select get_byte(adat,1) from test;
get_byte
----------
128
(1 row)
gkk=# select get_byte(adat,2) from test;
ERROR: byteaGetByte: index 2 out of range [0..1]
How to insert in a correct way?
Thanks,
Lajos
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: How to insert zeros into a bytea column?
@ 2002-02-23 21:04 Joe Conway <mail@joeconway.com>
parent: Iklódi Lajos <il@mithrandir.hu>
0 siblings, 0 replies; 2+ messages in thread
From: Joe Conway @ 2002-02-23 21:04 UTC (permalink / raw)
To: Iklódi Lajos <il@mithrandir.hu>; +Cc: 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@\200
(1 row)
See for more info:
http://www.us.postgresql.org/users-lounge/docs/7.2/postgres/datatype-binary.html
HTH,
Joe
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2002-02-23 21:04 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-02-23 20:16 How to insert zeros into a bytea column? Iklódi Lajos <il@mithrandir.hu>
2002-02-23 21:04 ` Joe Conway <mail@joeconway.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox