From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Hugh Mandeville" <hughmandeville(at)hotmail(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Re: Re: binary data |
Date: | 2001-06-22 14:22:32 |
Message-ID: | 3791.993219752@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
"Hugh Mandeville" <hughmandeville(at)hotmail(dot)com> writes:
> "Alex Pilosov" <alex(at)pilosoft(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Josh Berkus | 2001-06-22 15:07:40 | View performance question |
Previous Message | Tom Lane | 2001-06-22 13:54:27 | Re: select tbl1.attr1, number of tuples where tbl2.attr1=tbl1.attr1 |