Re: DBD::Pg (version 3.16.3) returns EMPTY char columns as 'undef'

From: Ian Lawrence Barwick <barwick(at)gmail(dot)com>
To: Matthias Apitz <guru(at)unixarea(dot)de>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: DBD::Pg (version 3.16.3) returns EMPTY char columns as 'undef'
Date: 2023-04-25 12:58:10
Message-ID: CAB8KJ=hp2HdjT46jX067T4LxoE7YuPG3c4hBoiT5_W1WnpkQJw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2023年4月25日(火) 21:42 Matthias Apitz <guru(at)unixarea(dot)de>:
>
>
> Hello,
>
> We're using the above DBD::Pg version on Linux together with PostgreSQL 15.1
> On fetch empty char columns are returned as (Perl) 'undef'
>
> while ( my @row_ary = $dba->FetchArray()) {
> foreach my $i (0..$#row_ary) {
> if ($row_ary[$i] eq undef) {
> print $row_ary[1] . "\n";
> next;
> }
> ...
> which later leads in our code to NULL values '\N' in the writing of a CSV-like export
> files. Ofc NULL values in the database are something else as '' char
> strings.
>
> How this must be distinguished with DBD::Pg?

"eq undef" looks very wrong there:

$ perl -e "printf(qq|%i\n|, '' eq undef);"
1
$ perl -e "printf(qq|%i\n|, defined '');"
1

You probably want "if (!defined $row_ary[$i])". And possibly warnings enabled:

$ perl -w -e "printf(qq|%i\n|, '' eq undef);"
Use of uninitialized value in string eq at -e line 1.
1
$ perl -w -e "printf(qq|%i\n|, defined '');"
1

Regards

Ian Barwick

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message postgresql439848 2023-04-25 14:31:27 Re: FW: Error!
Previous Message Erik Wienhold 2023-04-25 12:53:09 Re: psql:t_mstr.sql:994: ERROR: function to_char(numeric) does not exist