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

From: Francisco Olarte <folarte(at)peoplecall(dot)com>
To: Matthias Apitz <guru(at)unixarea(dot)de>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: SELECT d02name::bytea FROM ... && DBI::Pg
Date: 2019-10-10 16:46:02
Message-ID: CA+bJJbx2q0ZrnC2NmF1uaGMfJ8HBfBh08cW4JH1wEV-ZDYvnPw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Matthias:

On Thu, Oct 10, 2019 at 1:25 PM Matthias Apitz <guru(at)unixarea(dot)de> wrote:
> I can SELECT && print a column in hex with:
> pos71=# select d02name::bytea from d02ben where d02bnr = '00001048313' ;
> ...
> \x50c3a46461676f67697363686520486f6368736368756c65205765696e67617274656e2020 ...
>
> but when I use the same in Perl DBI::Pg with:
> $sth=$dbh->prepare( "select d02name::bytea from d02ben where d02bnr = '00001048313'");
...
> It prints the UTF-8 string and not the hex string:

May be because perl does not need the contents in hex DBI converts it
to a native string, which is very similar to a "bytea" inside the db (
not in the wire protocol, but it does a similar thing for numbers ).

Notice once you have a string in perl it is trivial to convert it to hex:
$ perl -e 'print(unpack("H*", "1234ABCD"),"\n")'
3132333441424344
$ perl -e 'print(unpack("H*", "día año"),"\n")'
64c3ad612061c3b16f

Francisco Olarte.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Matthias Apitz 2019-10-10 17:26:28 Re: SELECT d02name::bytea FROM ... && DBI::Pg
Previous Message Yessica Brinkmann 2019-10-10 16:38:07 Re: The connection to the server was lost. Attempting reset: Failed.