Re: bytea type - Mailing list pgsql-general

From Joe Conway
Subject Re: bytea type
Date
Msg-id 3DA58E70.5000603@joeconway.com
Whole thread Raw
In response to bytea type  (Felipe Schnack <felipes@ritterdosreis.br>)
List pgsql-general
Felipe Schnack wrote:
>   How I convert a bytea column to a varchar?

-- this is just to show that the \\000 is actually a single character in bytea
test=# select length('abc\\000def'::bytea);
  length
--------
       7
(1 row)

-- here's how to convert to varchar
test=# select encode('abc\\000def'::bytea,'escape')::varchar;
    encode
------------
  abc\000def
(1 row)

Note that certain characters get escaped because they are not representable in
text or varchar. See:
http://www.postgresql.org/idocs/index.php?functions-string.html
for (a bit) more on the encode function.

Joe


pgsql-general by date:

Previous
From: Joe Conway
Date:
Subject: Re: [BUGS] user name lost from dictionary
Next
From: Richard Huxton
Date:
Subject: Re: access time performance problem