From: Joe Conway <mail@joeconway.com>
To: Achilleus Mantzios <achill@matrix.gatewaynet.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Encoding bytea
Date: Wed, 03 Mar 2004 14:59:14 -0800
Message-ID: <40466342.1000608@joeconway.com> (raw)
In-Reply-To: <Pine.LNX.4.44.0403031457110.2444-100000@matrix.gatewaynet.com>
References: <Pine.LNX.4.44.0403031457110.2444-100000@matrix.gatewaynet.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mail@joeconway.com, achill@matrix.gatewaynet.com
Subject: Re: Encoding bytea
In-Reply-To: <40466342.1000608@joeconway.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox