Re: PostgreSQL arrays and DBD

From: SCassidy(at)overlandstorage(dot)com
To: Александр Чешев <alex(dot)cheshev(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, pgsql-general-owner(at)postgresql(dot)org
Subject: Re: PostgreSQL arrays and DBD
Date: 2008-08-14 18:12:17
Message-ID: OF2E635A33.32B5A740-ON882574A5.0063AF38-882574A5.00640356@overlandstorage.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

pgsql-general-owner(at)postgresql(dot)org wrote on 08/14/2008 01:21:26 AM:

> 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 .

This can't be the whole program, since you show line 4 (per the error
message), which is marked as line 4, but you never connected to the
database.
Also, I would put parentheses around the expression in the while, to make
sure the precedence is what you think it is.

I have a slightly different DBD::Pg version, so I can't test it exactly.
Does your version support array types? I don't think mine does (older
version).

Susan

----------------------------------------------------
Tiered Data Protection Made Simple
http://www.overlandstorage.com/
----------------------------------------------------

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Davis 2008-08-14 19:06:26 Re: Custom sort
Previous Message juliano.freitas 2008-08-14 18:03:35 Experiences with BLOB + PostgreSQL