bytea question

Started by Maximilian Tyrtaniaover 16 years ago2 messagesgeneral
Jump to latest
#1Maximilian Tyrtania
maximilian.tyrtania@byte-employer.de

PG 8.4.0 running on Mac OS 10.6.1

Could anyone tell me why the bytea datatypes seems to like some bytes better
than others?

testdb=# create table byteatest(blob bytea);
CREATE TABLE
testdb=# insert into byteatest (blob) values (E'\\007');
INSERT 0 1
testdb=# insert into byteatest (blob) values (E'\\008');
ERROR: invalid input syntax for type bytea
LINE 1: insert into byteatest (blob) values (E'\\008');

Or also:

testdb=# SELECT E'\\001'::bytea;
bytea
-------
\001
(1 row)

testdb=# SELECT E'\\008'::bytea;
ERROR: invalid input syntax for type bytea
LINE 1: SELECT E'\\008'::bytea;

As far as I can see i followed the escaping rules given in

http://www.postgresql.org/docs/current/static/datatype-binary.html

Thanks,

Maximilian Tyrtania

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Maximilian Tyrtania (#1)
Re: bytea question

On Mon, 28 Sep 2009, Maximilian Tyrtania wrote:

testdb=# create table byteatest(blob bytea);
CREATE TABLE
testdb=# insert into byteatest (blob) values (E'\\007');
INSERT 0 1
testdb=# insert into byteatest (blob) values (E'\\008');
ERROR: invalid input syntax for type bytea
LINE 1: insert into byteatest (blob) values (E'\\008');

Or also:

testdb=# SELECT E'\\001'::bytea;
bytea
-------
\001
(1 row)

testdb=# SELECT E'\\008'::bytea;
ERROR: invalid input syntax for type bytea
LINE 1: SELECT E'\\008'::bytea;

As far as I can see i followed the escaping rules given in

http://www.postgresql.org/docs/current/static/datatype-binary.html

From that:

"When entering bytea values, octets of certain values must be escaped (but
all octet values can be escaped) when used as part of a string literal in
an SQL statement. In general, to escape an octet, convert it into its
three-digit octal value and precede it by two backslashes."

008 isn't a valid octal value, you'd want 010 to represent 8.