Thread: bytea type

bytea type

From
Felipe Schnack
Date:
  How I convert a bytea column to a varchar?
--

Felipe Schnack
Analista de Sistemas
felipes@ritterdosreis.br
Cel.: (51)91287530
Linux Counter #281893

Faculdade Ritter dos Reis
www.ritterdosreis.br
felipes@ritterdosreis.br
Fone/Fax.: (51)32303328


Re: bytea type

From
Joe Conway
Date:
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