Re: Cast text to bytea: the Solution - Mailing list pgsql-general

From Alvar Freude
Subject Re: Cast text to bytea: the Solution
Date
Msg-id 1465860000.1070457807@gnarzelwicht.delirium-arts.de
Whole thread Raw
In response to Re: Cast text to bytea  (Alvar Freude <alvar@a-blast.org>)
List pgsql-general
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

- -- Alvar Freude <alvar@a-blast.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-----


pgsql-general by date:

Previous
From: "Claudio Lapidus"
Date:
Subject: Re: Money data type in PostgreSQL?
Next
From: Barbara Lindsey
Date:
Subject: Re: DBD::Pg problem