Re: dynamic crosstab

From: Andy Colson <andy(at)squeakycode(dot)net>
To: Pierre Chevalier <pierre(dot)chevalier1967(at)free(dot)fr>, PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: dynamic crosstab
Date: 2010-01-29 15:14:38
Message-ID: 4B62FB5E.4020306@squeakycode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/28/2010 5:51 PM, Pierre Chevalier wrote:
>>
>> while ( my @list = $get->fetchrow_array)
>> {
>> print join(',', @list), "\n";
>> }

> It throws some insulting messages, though:
>
> Use of uninitialized value $list[5] in join or string at
> ./crosstab_perl.pl line 24.
> Use of uninitialized value $list[6] in join or string at
> ./crosstab_perl.pl line 24.
> Use of uninitialized value $list[7] in join or string at
> ./crosstab_perl.pl line 24.

Yeah, you can ignore them. Fields that are null in the database will be
converted to undef in perl, which when printed spits out that warning.
Right before the print, we could test for undef and set them to empty
string like:

map { if (!defined($_)) {$_ = '';}} @list;

so the while loop would look like:

while ( my @list = $get->fetchrow_array)
{
map { if (!defined($_)) {$_ = '';}} @list;
print join(',', @list), "\n";
}

-Andy

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Devrim GÜNDÜZ 2010-01-29 15:49:43 Re: [GENERAL] Versions RSS page is missing version(s)
Previous Message Dave Page 2010-01-29 15:08:57 Re: [GENERAL] Versions RSS page is missing version(s)