X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 74513D1D0AE for ; Wed, 3 Mar 2004 23:01:13 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 25719-06 for ; Wed, 3 Mar 2004 19:01:02 -0400 (AST) Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by svr1.postgresql.org (Postfix) with ESMTP id 04981D1D165 for ; Wed, 3 Mar 2004 19:00:52 -0400 (AST) Received: from [206.19.64.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.1.8) with ESMTP-TLS id 1039100; Wed, 03 Mar 2004 14:56:47 -0800 Message-ID: <40466342.1000608@joeconway.com> Date: Wed, 03 Mar 2004 14:59:14 -0800 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6) Gecko/20040113 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Achilleus Mantzios Cc: pgsql-sql@postgresql.org Subject: Re: Encoding bytea References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/29 X-Sequence-Number: 17128 Achilleus Mantzios wrote: > is there a way to encode a bytea in such a way that the resulting > text stream be readily available (\\ escaped for unprintable chars) for > usage in an insert statement? > > None of base64,hex,escape options in encode() seem to produce > anything close. > > This is meant to be used with generating insert statements in xml files > for remote processing. Is this what you need? create table t(f bytea); insert into b values ('a\\003\\000\\001b'); create or replace function bytea2text(bytea) returns text as ' begin return $1; end; ' language plpgsql; regression=# select 'insert into t values(' || quote_literal(bytea2text(f)) || ');' from t; ?column? -------------------------------------------- insert into t values('a\\003\\000\\001b'); (1 row) regression=# insert into t values('a\\003\\000\\001b'); INSERT 292656 1 HTH, Joe