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

From: Matthias Apitz <guru(at)unixarea(dot)de>
To: Ian Lawrence Barwick <barwick(at)gmail(dot)com>
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-26 05:32:58
Message-ID: ZEi3iqLJMSoMkXfx@pureos
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

El día martes, abril 25, 2023 a las 09:58:10 +0900, Ian Lawrence Barwick escribió:

> "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:
>
> ...

Ian,

Thanks for this hint. It fixed it. I modified the code to:

...
foreach my $i (0..$#row_ary) {
if (!defined $row_ary[$i]) {
printf $row_ary[0] . " | " . $row_ary[1] . " | " . $row_ary[2] . "\n";
next;
}

set one row to have a NULL value (others have '' or a real string for
the column varvalue):

testdb=# update adm_partab set varvalue = NULL where varname='DocumentUploadSshPassw';
UPDATE 1

testdb=# \pset null '<null>'
Null-Anzeige ist »<null>«.

testdb=# select * from adm_partab where varname='DocumentUploadSshPassw';
product | varname | varvalue
---------+------------------------+----------
1 | DocumentUploadSshPassw | <null>

and run the modiefied code which prints only the row with the NULL
value, exports everything fine and the NULL value as '\N':

~sisis/sc/dbtool < unl 2>&1 | more
connected to Pg:testdb
begin operation: UNLOAD (adm_partab)
1 | DocumentUploadSshPassw |
366 rows unloaded...

grep -C3 '|\\N' adm_partab.load
2|CIR_auto_idm_informieren|N
2|CIR_GebMahn_SO|N
2|CIR_BR_Immer_Benachrichtigen|N
1|DocumentUploadSshPassw|\N <***************
2|CIR_AutoTempMedien|N
2|CIR_PrintCmd_List_Ascii|/opt/lib/sisis/bin/AsciiPrint.sh
2|CIR_Such_Kategorie_4|902 Schlagwort

even the warning is printed for this perl line 1196:

~sisis/sc/dbtool < unl 2>&1 | grep 1196
Use of uninitialized value $row_ary[2] in concatenation (.) or string at /home/sisis/sc/dbtool.pl line 1196.

Thanks again and

Kind Regards

matthias

--
Matthias Apitz, ✉ guru(at)unixarea(dot)de, http://www.unixarea.de/ +49-176-38902045
Public GnuPG key: http://www.unixarea.de/key.pub

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Amit Kapila 2023-04-26 05:56:01 Re: Support logical replication of DDLs
Previous Message Masahiko Sawada 2023-04-26 04:31:17 Re: Support logical replication of DDLs