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 20BEDD1C9D0 for ; Thu, 4 Mar 2004 07:58:24 +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 63360-03 for ; Thu, 4 Mar 2004 03:58:06 -0400 (AST) Received: from matrix.gatewaynet.com (matrix.gatewaynet.com [217.19.69.50]) by svr1.postgresql.org (Postfix) with ESMTP id CDC68D1C968 for ; Thu, 4 Mar 2004 03:58:05 -0400 (AST) Received: from matrix.gatewaynet.com (localhost.localdomain [127.0.0.1]) by matrix.gatewaynet.com (8.12.8/8.12.8) with ESMTP id i247sLNu004629; Thu, 4 Mar 2004 09:54:22 +0200 Received: from localhost (achill@localhost) by matrix.gatewaynet.com (8.12.8/8.12.8/Submit) with ESMTP id i247sLdg004625; Thu, 4 Mar 2004 09:54:21 +0200 Date: Thu, 4 Mar 2004 09:54:21 +0200 (EET) From: Achilleus Mantzios To: Joe Conway Cc: pgsql-sql@postgresql.org Subject: Re: Encoding bytea In-Reply-To: <40466342.1000608@joeconway.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/32 X-Sequence-Number: 17131 O kyrios Joe Conway egrapse stis Mar 3, 2004 : > 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? Yes thanx. ( i always forget about the casting function trick) > > 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 > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org > -- -Achilleus