Re: SELECT d02name::bytea FROM ... && DBI::Pg - Mailing list pgsql-general

From Andrew Gierth
Subject Re: SELECT d02name::bytea FROM ... && DBI::Pg
Date
Msg-id 87zhi5vm0z.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to SELECT d02name::bytea FROM ... && DBI::Pg  (Matthias Apitz <guru@unixarea.de>)
List pgsql-general
>>>>> "Matthias" == Matthias Apitz <guru@unixarea.de> writes:

 Matthias> Hello,

 Matthias> I can SELECT && print a column in hex with:

 Matthias> pos71=# select d02name::bytea from d02ben where d02bnr = '00001048313' ;

If your intention is to see the raw bytes of the stored text value, for
example to check the encoding, then you should not do it that way.
Casting from text to bytea does NOT do what you think.

Instead use  convert_to(d02name,'SQL_ASCII')  (yes, always specify
SQL_ASCII regardless of what encoding you think it should be in, since
the actual meaning of SQL_ASCII is "no conversions"). For readability,
you may then want to wrap that as
encode(convert_to(d02name,'SQL_ASCII'),'escape')  which will keep the
ASCII characters but use \nnn escapes for non-ascii.

-- 
Andrew (irc:RhodiumToad)



pgsql-general by date:

Previous
From: Andrew Gierth
Date:
Subject: Re: day interval
Next
From: Tom Lane
Date:
Subject: Re: day interval