Re: Re: Re: binary data - Mailing list pgsql-sql

From Tom Lane
Subject Re: Re: Re: binary data
Date
Msg-id 3791.993219752@sss.pgh.pa.us
Whole thread Raw
In response to Re: Re: binary data  ("Hugh Mandeville" <hughmandeville@hotmail.com>)
Responses Re: Re: Re: binary data
List pgsql-sql
"Hugh Mandeville" <hughmandeville@hotmail.com> writes:
> "Alex Pilosov" <alex@pilosoft.com> wrote in message
>> The rules for escaping things you want to throw at it are tricky though.
>> (and same for unescaping things you get back from database).

> test=# INSERT INTO log (data) VALUES ('special chars \n \001 \002');
> INSERT 61651 1
> test=# INSERT INTO log (data) VALUES ('null \000 null');
> INSERT 61652 1
> test=# SELECT octet_length(data), data FROM log;
>  octet_length |             data
> --------------+------------------------------
>            10 | plain text
>            19 | special chars \012 \001 \002
>             5 | null
> (3 rows)

He did say the rules for escaping things are tricky ;-).  You need to
double the backslashes, because interpretation of the string literal
takes off one level of backslashing before bytea ever sees it:

regression=# INSERT INTO log (data) VALUES ('null \\000 null');
INSERT 273181 1
regression=# SELECT octet_length(data), data FROM log;octet_length |             data
--------------+------------------------------          10 | plain text          19 | special chars \012 \001 \002
   5 | null          11 | null \000 null
 
(4 rows)

        regards, tom lane


pgsql-sql by date:

Previous
From: Alex Pilosov
Date:
Subject: Re: Help with a double left join
Next
From: "Josh Berkus"
Date:
Subject: View performance question