Re: PostgreSQL arrays and DBD

From: Decibel! <decibel(at)decibel(dot)org>
To: Александр Чешев <alex(dot)cheshev(at)gmail(dot)com>, David Fetter <david(at)fetter(dot)org>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: PostgreSQL arrays and DBD
Date: 2008-08-22 05:36:19
Message-ID: 04D6CE50-D221-40B8-8028-C7E30C27DEF2@decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Don't know the answer, but I'm betting that Dave does :)

On Aug 14, 2008, at 3:31 AM, Александр Чешев wrote:
> I create a table:
>
> CREATE TABLE groups (
> group_id serial PRIMARY KEY,
> name varchar(64) UNIQUE NOT NULL,
> guests integer[] DEFAULT '{}'
> )
>
> I add a new record to the table:
>
> INSERT INTO groups (name) VALUES ('My friends');
>
> Now the table contains 1 record:
>
> | group_id | name | guests
> +----------+------------+--------
> | 1 | My friends | {}
>
> I read the new record from the table using DBI:
>
> my $sth = $dbh->prepare(qq/SELECT * FROM groups/);
> $sth->execute();
> my (@guests, $group);
> push(@guests, $group) while $group = $sth->fetchrow_hashref(); #
> Line 4
> print $guests[0]->{guests}->[0]; # Why ({group_id=>1, name=>'My
> friends', guests=>[0]}) ?
>
> Output of the script:
>
> Argument "" isn't numeric in null operation at ./guestmanager.pl
> line 4
> 0
>
> DBD should return a reference to an empty array. But DBD returned
> the reference to the array containing 1 element (0). How can I have
> a different result:
>
> ({group_id=>1, name=>'My friends', guests=>[]})
>
> PS
> Version of DBD::Pg is 2.9.0 .

--
Decibel!, aka Jim C. Nasby, Database Architect decibel(at)decibel(dot)org
Give your computer some brain candy! www.distributed.net Team #1828

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Greg Sabino Mullane 2008-08-22 17:19:00 Re: PostgreSQL arrays and DBD
Previous Message Michael Meskes 2008-08-20 16:51:30 Re: ecpg 'set' failure using host vars