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

Поиск
Список
Период
Сортировка
От Matthias Apitz
Тема Re: DBD::Pg (version 3.16.3) returns EMPTY char columns as 'undef'
Дата
Msg-id ZEi3iqLJMSoMkXfx@pureos
обсуждение исходный текст
Ответ на Re: DBD::Pg (version 3.16.3) returns EMPTY char columns as 'undef'  (Ian Lawrence Barwick <barwick@gmail.com>)
Список 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@unixarea.de, http://www.unixarea.de/ +49-176-38902045
Public GnuPG key: http://www.unixarea.de/key.pub



В списке pgsql-general по дате отправления:

Предыдущее
От: postgresql439848@heinz-it.de
Дата:
Сообщение: Re: FW: Error!
Следующее
От: Tushar Takate
Дата:
Сообщение: PostgreSQL in-transit compression for a client connection