Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id E3D286502D2 for ; Thu, 14 Aug 2008 05:31:20 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 35113-08 for ; Thu, 14 Aug 2008 05:31:14 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from qb-out-0506.google.com (qb-out-0506.google.com [72.14.204.229]) by postgresql.org (Postfix) with ESMTP id 5508B6502B5 for ; Thu, 14 Aug 2008 05:31:17 -0300 (ADT) Received: by qb-out-0506.google.com with SMTP id d8so498224qbc.23 for ; Thu, 14 Aug 2008 01:31:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type; bh=EuQ8+XIxRZe4lwodFg8fbEbqWSm334ZCNYu4wJsEkO8=; b=MlaXZ4PzacDZu4q0Mv8Rlk7UxMjvSaG9Ds+Cl1NranPvHepEo3m6FA9wWGC2D0BH1h +9YoAamUMtxrgb95rjJVNnwkGujF7J0BZgOtmPW3uc/8b7f0Sutxj67MArjjcf82wPGT 8WIDtnc7X4O1WMLUoxxgJ2GWzqUMo9TmpiVng= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=nfiQanb8xUYxfSqTnxThV6LQMs1kZhVxp33RBABKix9fx/as2BnZ7sewGPPds4gt7r fv7Q2c3CaWcfIsFZ5SZUbtZDrLS/z1uFs6xKZavtCvAO3iprW7IBH3ZSVQTpYFiy7Xrz bdvwU/2Wl55PN36zys8gI3nx4IaVeL5HAbUkA= Received: by 10.210.117.1 with SMTP id p1mr1029595ebc.53.1218702675442; Thu, 14 Aug 2008 01:31:15 -0700 (PDT) Received: by 10.210.116.2 with HTTP; Thu, 14 Aug 2008 01:31:15 -0700 (PDT) Message-ID: <6e38c1070808140131n78ca8496i2f57d0cd71fbea11@mail.gmail.com> Date: Thu, 14 Aug 2008 19:31:15 +1100 From: "=?KOI8-R?B?4czFy9PBzsTSIP7F28XX?=" To: pgsql-interfaces@postgresql.org Subject: PostgreSQL arrays and DBD MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_87627_15596138.1218702675415" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200808/5 X-Sequence-Number: 6780 ------=_Part_87627_15596138.1218702675415 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 . ------=_Part_87627_15596138.1218702675415 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
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 .
------=_Part_87627_15596138.1218702675415--