PostgreSQL arrays and DBD

From: Александр Чешев <alex(dot)cheshev(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: PostgreSQL arrays and DBD
Date: 2008-08-14 08:21:26
Message-ID: 6e38c1070808140121u340e6696o60e97fedff61b57a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello.

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 .

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joris Dobbelsteen 2008-08-14 09:14:25 Re: Referential integrity vulnerability in 8.3.3
Previous Message Pavel Stehule 2008-08-14 07:59:17 Re: cannot use result of (insert .. returning)