Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5MEMba05586 for ; Fri, 22 Jun 2001 10:22:38 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id f5MEMW303794; Fri, 22 Jun 2001 10:22:32 -0400 (EDT) To: "Hugh Mandeville" cc: pgsql-sql@postgresql.org Subject: Re: Re: Re: binary data In-reply-to: <9gtovc$mnr$1@news.tht.net> References: <9gtovc$mnr$1@news.tht.net> Comments: In-reply-to "Hugh Mandeville" message dated "Thu, 21 Jun 2001 17:29:41 -0400" Date: Fri, 22 Jun 2001 10:22:32 -0400 Message-ID: <3791.993219752@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200106/369 X-Sequence-Number: 3659 "Hugh Mandeville" writes: > "Alex Pilosov" 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