Re: SELECT d02name::bytea FROM ... && DBI::Pg

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: Matthias Apitz <guru(at)unixarea(dot)de>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: SELECT d02name::bytea FROM ... && DBI::Pg
Date: 2019-10-12 18:51:57
Message-ID: 87zhi5vm0z.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>>>>> "Matthias" == Matthias Apitz <guru(at)unixarea(dot)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)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2019-10-12 20:27:11 Re: day interval
Previous Message Andrew Gierth 2019-10-12 17:48:16 Re: day interval