Bytea to Text problems

From: John McCawley <nospam(at)hardgeus(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Bytea to Text problems
Date: 2006-09-12 15:56:09
Message-ID: 4506D899.5020807@hardgeus.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I've searched high and low, and all I've found is people being chided
for trying to convert from Bytea to text :)

When I first designed my database, I simply didn't understand the
purpose of bytea, I didn't actually realize that there *was* a text data
type. (Actually, I was porting from a MS SQL database, and if I
remember correctly, PgAdmin actually made the decision for me) I now
need to convert my field from bytea to text, but there doesn't seem to
be a clean way to do it. So far I have done the following:

alter table tbl_inventory ADD longdescription_new text;

update tbl_inventory SET longdescription_new = encode(longdescription,
'escape');

update tbl_inventory SET longdescription_new =
replace(longdescription_new, '\256', '\n') WHERE longdescription_new
LIKE '%\256%';

(ad infinitum)

The problem is that encode, obviously, escapes a metric ton of stuff,
and I have no idea *what* is being encoded, or even what it is being
encoded into, other than exhaustively digging through my data and
comparing the escape codes to the original text. Is there a chart
somewhere that will show me? Is there a script that will do this?

John

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Francisco Reyes 2006-09-12 16:04:47 Re: Superuser lost access to particular database
Previous Message Andrew Sullivan 2006-09-12 15:36:17 Re: Child program using parent program's transaction?