|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
PostgreSQL arrays and DBDHello.
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 . |
|
|
Re: PostgreSQL arrays and DBDDon'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@... Give your computer some brain candy! www.distributed.net Team #1828 |
|
|
Re: PostgreSQL arrays and DBD-----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 > 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: This was fixed: version 2.9.2 of DBD::Pg should behave as you expect with regards to empty integer arrays. This was asked and answered on the dbi list, but no ccs went to the interfaces list - sorry about that. http://www.nntp.perl.org/group/perl.dbi.users/2008/08/msg33162.html - -- Greg Sabino Mullane greg@... End Point Corporation PGP Key: 0x14964AC8 200808221317 http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 -----BEGIN PGP SIGNATURE----- iEYEAREDAAYFAkiu9NAACgkQvJuQZxSWSsiCpQCgnpwjoL8x937IT65cbl14zwb9 S94AnA4YBnjXGec7gnUum0ZSK/hIyHWn =CXQx -----END PGP SIGNATURE----- -- Sent via pgsql-interfaces mailing list (pgsql-interfaces@...) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-interfaces |
| Free embeddable forum powered by Nabble | Forum Help |