From: Александр Чешев <alex.cheshev@gmail.com>
To: pgsql-interfaces@postgresql.org
Subject: PostgreSQL arrays and DBD
Date: Thu, 14 Aug 2008 19:31:15 +1100
Message-ID: <6e38c1070808140131n78ca8496i2f57d0cd71fbea11@mail.gmail.com> (raw)
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 .
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: alex.cheshev@gmail.com
Subject: Re: PostgreSQL arrays and DBD
In-Reply-To: <6e38c1070808140131n78ca8496i2f57d0cd71fbea11@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox