PostgreSQL arrays and DBD

Поиск
Список
Период
Сортировка
От Александр Чешев
Тема PostgreSQL arrays and DBD
Дата
Msg-id 6e38c1070808140131n78ca8496i2f57d0cd71fbea11@mail.gmail.com
обсуждение исходный текст
Ответы Re: PostgreSQL arrays and DBD  (Decibel! <decibel@decibel.org>)
Список pgsql-interfaces
<div dir="ltr"><div class="ArwC7c ckChnd" id=":1kp"><div dir="ltr"><span style="font-family: courier
new,monospace;">Hello.</span><brstyle="font-family: courier new,monospace;" /><br style="font-family: courier
new,monospace;"/><span style="font-family: courier new,monospace;">I create a table:</span><br style="font-family:
couriernew,monospace;" /><br style="font-family: courier new,monospace;" /><span style="font-family: courier
new,monospace;">CREATETABLE groups (</span><br style="font-family: courier new,monospace;" /><span style="font-family:
couriernew,monospace;">  group_id serial PRIMARY KEY,</span><br style="font-family: courier new,monospace;" /><span
style="font-family:courier new,monospace;">  name varchar(64) UNIQUE NOT NULL,</span><br style="font-family: courier
new,monospace;"/><span style="font-family: courier new,monospace;">  guests integer[] DEFAULT '{}'</span><br
style="font-family:courier new,monospace;" /><span style="font-family: courier new,monospace;">)</span><br
style="font-family:courier new,monospace;" /><br style="font-family: courier new,monospace;" /><span
style="font-family:courier new,monospace;">I add a new record to the table:</span><br style="font-family: courier
new,monospace;"/><br style="font-family: courier new,monospace;" /><span style="font-family: courier
new,monospace;">INSERTINTO groups (name) VALUES ('My friends');</span><br style="font-family: courier new,monospace;"
/><brstyle="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;">Now the table
contains1 record:</span><br style="font-family: courier new,monospace;" /><br style="font-family: courier
new,monospace;"/><span style="font-family: courier new,monospace;">| group_id |    name    | guests</span><br
style="font-family:courier new,monospace;" /><span style="font-family: courier
new,monospace;">+----------+------------+--------</span><brstyle="font-family: courier new,monospace;" /><span
style="font-family:courier new,monospace;">|        1 | My friends | {}</span><span style="font-family: courier
new,monospace;"></span><brstyle="font-family: courier new,monospace;" /><br style="font-family: courier new,monospace;"
/><spanstyle="font-family: courier new,monospace;">I read the new record from the table using DBI:</span><br
style="font-family:courier new,monospace;" /><br style="font-family: courier new,monospace;" /><span
style="font-family:courier new,monospace;">my $sth = $dbh->prepare(qq/SELECT * FROM groups/);</span><br
style="font-family:courier new,monospace;" /><span style="font-family: courier
new,monospace;">$sth->execute();</span><brstyle="font-family: courier new,monospace;" /><span style="font-family:
couriernew,monospace;">my (@guests, $group);</span><br style="font-family: courier new,monospace;" /><span
style="font-family:courier new,monospace;">push(@guests, $group) while $group = $sth->fetchrow_hashref(); # Line
4</span><brstyle="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;">print
$guests[0]->{guests}->[0];# Why ({group_id=>1, name=>'My friends', </span><b style="font-family: courier
new,monospace;">guests=>[0]</b><spanstyle="font-family: courier new,monospace;">}) ?</span><br style="font-family:
couriernew,monospace;" /><br style="font-family: courier new,monospace;" /><span style="font-family: courier
new,monospace;">Outputof the script:</span><br style="font-family: courier new,monospace;" /><br style="font-family:
couriernew,monospace;" /><span style="font-family: courier new,monospace;">Argument "" isn't numeric in null operation
at./guestmanager.pl line 4</span><br style="font-family: courier new,monospace;" /><b style="font-family: courier
new,monospace;">0</b><brstyle="font-family: courier new,monospace;" /><br style="font-family: courier new,monospace;"
/><spanstyle="font-family: courier new,monospace;">DBD should return a reference to an empty array. But DBD returned
thereference to the array containing 1 element (0). How can I have a different result:</span><br style="font-family:
couriernew,monospace;" /><br style="font-family: courier new,monospace;" /><span style="font-family: courier
new,monospace;">({group_id=>1,name=>'My friends', </span><b style="font-family: courier
new,monospace;">guests=>[]</b><spanstyle="font-family: courier new,monospace;">})</span><br style="font-family:
couriernew,monospace;" /><br style="font-family: courier new,monospace;" /><span style="font-family: courier
new,monospace;">PS</span><brstyle="font-family: courier new,monospace;" /><span style="font-family: courier
new,monospace;">Versionof DBD::Pg is 2.9.0 .</span></div></div></div> 

В списке pgsql-interfaces по дате отправления:

Предыдущее
От: Vincent Predoehl
Дата:
Сообщение: Re: connecting with libpq interface
Следующее
От: Bosco Rama
Дата:
Сообщение: ecpg 'set' failure using host vars