[Dbix-class] Making DBD::Pg to return Postgres arrays as Perl arrays
Adam Sjøgren
adsj at novozymes.com
Thu May 7 11:30:45 GMT 2015
I wrote:
> When I insert new rows where the field has a Perl-array as the value,
> DBIx::Class+DBD::Pg automatically stores them in the database, as hoped
> - nice!
> But when I read the field again, I get the textual "Postgres-encoded"
> representation back (i.e. a string like '{"(a,b,c)","(d,e,f)"}').
After looking more closely on this:
Simple arrays work out of the box, i.e. text[] I can read/write and
values are automatically converted from Perl arrays when writing to the
database, and converted back to Perl arrays when reading.
The problem I have is only when my datatype is a (custom) tuple.
I.e. in Postgres I have:
CREATE TYPE entry AS (tag TEXT, created TIMESTAMP, notes TEXT, initials TEXT);
ALTER TABLE vehicle ADD COLUMN entrylist entry ARRAY;
I would like to be able to do:
$schema->resultset('Vehicle')->create({ entrylist=>[
[ 'a', '2015-05-07', 'info', 'adsj' ],
[ 'b', '2015-05-07', 'more', 'adsj' ],
] });
and I was hoping that there was a way to configure DBIx::Class/DBD::Pg
for that to work (it doesn't, the list-ref of list-refs gets sent to the
database as '{{"a",...},{"b",...}}' which should be '{("a",...),("b",...)}',
and Postgres complains).
... and I was hoping that when reading from the database, I could
automatically get a list-ref of list-refs back.
Maybe I was hoping for too much - I just wanted to check that I wasn't
missing something obvious, before hacking together a parser for
Postgres' format.
Best regards,
Adam
Adding Cc to the DBD::Pg mailing list, as it now looks to me to perhaps
not just be me not configuring DBIx::Class properly.
--
Adam Sjøgren
adsj at novozymes.com
More information about the DBIx-Class
mailing list