Re: Cast text to bytea: the Solution

From: Alvar Freude <alvar(at)a-blast(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Cast text to bytea: the Solution
Date: 2003-12-03 13:23:27
Message-ID: 1465860000.1070457807@gnarzelwicht.delirium-arts.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

- -- Alvar Freude <alvar(at)a-blast(dot)org> wrote:
>
> odem=> UPDATE forum_gtree SET gid2=(DECODE(gid::text, 'escape'));
> ERROR: decode: Bad input string for type bytea

the solution is: backslashes in the text column are interpreted as escapes.
So: they must be marked escaped first. Replacing "\" with "\\" does this:

UPDATE table SET bytea_col =
(decode(replace(text_col, '\\', '\\\\'), 'escape'));

This seems to work and looks like there are the correct values in the new
column ...

Ciao
Alvar

- --
** Alvar C.H. Freude -- http://alvar.a-blast.org/
** Berufsverbot? http://odem.org/aktuelles/staatsanwalt.de.html
** ODEM.org-Tour: http://tour.odem.org/
** Informationsgesellschaft: http://www.wsis-koordinierungskreis.de/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (FreeBSD)

iD8DBQE/zePPOndlH63J86wRAmEaAJ9LAWvLFwekca58BTWYYBuPgWrawACeJRjl
POrmVVWkT0+XmF7clqBtKlA=
=wH3M
-----END PGP SIGNATURE-----

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Barbara Lindsey 2003-12-03 13:25:11 Re: DBD::Pg problem
Previous Message Claudio Lapidus 2003-12-03 13:09:58 Re: Money data type in PostgreSQL?