Skip site navigation (1) Skip section navigation (2)

PostgreSQL arrays and DBD

From: Александр Чешев <alex(dot)cheshev(at)gmail(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: PostgreSQL arrays and DBD
Date: 2008-08-14 08:31:15
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces

I create a table:

  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/);
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 ./ line 4

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

({group_id=>1, name=>'My friends', *guests=>[]*})

Version of DBD::Pg is 2.9.0 .


pgsql-interfaces by date

Next:From: Bosco RamaDate: 2008-08-16 03:47:49
Subject: ecpg 'set' failure using host vars
Previous:From: Vincent PredoehlDate: 2008-08-11 15:10:44
Subject: Re: connecting with libpq interface

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group