<div dir="ltr"><div class="gmail_default" style><font face="arial, helvetica, sans-serif"> { data_type => "integer[]", ... }</font><br></div><div class="gmail_default" style><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default" style><font face="arial, helvetica, sans-serif">works for me?</font></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 7 May 2015 at 10:17, Adam Sjøgren <span dir="ltr"><<a href="mailto:adsj@novozymes.com" target="_blank">adsj@novozymes.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Hi.<br>
<br>
I have a Postgres database with some fields that are defined as arrays<br>
in the database.<br>
<br>
When I insert new rows where the field has a Perl-array as the value,<br>
DBIx::Class+DBD::Pg automatically stores them in the database, as hoped<br>
- nice!<br>
<br>
But when I read the field again, I get the textual "Postgres-encoded"<br>
representation back (i.e. a string like '{"(a,b,c)","(d,e,f)"}').<br>
<br>
It looks to me like DBD::Pg can expand these to Perl arrays, given the<br>
correct type of the field.<br>
<br>
My question is: How do I specify this with DBIx::Class?<br>
<br>
I have tried:<br>
<br>
__PACKAGE__->add_columns($field_name=>{ data_type=>'array' });<br>
__PACKAGE__->inflate_column($field_name=>{ inflate=>sub { ... },. deflate=>sub {...} );<br>
<br>
in various combinations (pg_type, data_type)=>('array', 'pg_anyarray',<br>
DBD::Pg::PG_ANYARRAY), but I seem to get the textual representation in<br>
the inflator sub regardless.<br>
<br>
What I would really like, is to get the array back as a Perl array.<br>
<br>
I can do the parsing myself, but I think DBD::Pg would be better and<br>
faster at it.<br>
<br>
(I need the inflate_column() call, because after getting the array in, I<br>
need to do some rearranging.)<br>
<br>
I have browsed in the documentation of DBD::Pg and DBIx::Class, but my<br>
search-fu is failing me.<br>
<br>
(E.g. the cookbook mentions how to store arrays:<br>
<br>
* <a href="https://metacpan.org/pod/DBIx::Class::Manual::Cookbook#Working-with-PostgreSQL-array-types" target="_blank">https://metacpan.org/pod/DBIx::Class::Manual::Cookbook#Working-with-PostgreSQL-array-types</a><br>
<br>
but not how to read them.)<br>
<br>
Any pointers?<br>
<br>
Thanks,<br>
<br>
Adam<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Adam Sjøgren<br>
<a href="mailto:adsj@novozymes.com">adsj@novozymes.com</a><br>
<br>
_______________________________________________<br>
List: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class" target="_blank">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class</a><br>
IRC: <a href="http://irc.perl.org#dbix-class" target="_blank">irc.perl.org#dbix-class</a><br>
SVN: <a href="http://dev.catalyst.perl.org/repos/bast/DBIx-Class/" target="_blank">http://dev.catalyst.perl.org/repos/bast/DBIx-Class/</a><br>
Searchable Archive: <a href="http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk" target="_blank">http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk</a></font></span></blockquote></div><br></div>