[Dbix-class] PostgreSQL's date_part in recent versions of DBIx::Class

Peter Rabbitson rabbit+dbic at rabbit.us
Sun Jan 15 09:04:35 GMT 2012


On Sat, Jan 14, 2012 at 09:14:18PM +0100, Xavier Robin wrote:
> Hi,
> 
> I'm trying to upgrade my Catalyst application. It is currently running
> fine in Perl 5.12.2 with DBIx::Class 0.08124. I'm trying to upgrade to
> perl 5.14.2, with the latest DBIx::Class from CPAN, namely 0.08196.
> 
> 
> Here is the problematic part of my Controller:
> 
> > 		select => [ "date_part('year', created)" ],
> 
> I can't find how I should be doing this exactly... would you please give
> me some advice? How would you get the list of years present in a
> timestamp column?
> 

What you are experiencing is fallout from API misuse. What you told DBIC
above is "select me a column (literally) named q!date_part('year', created)!.
Before DBIC would not do additional processing and your weirdly named
"column" would be ent to the RDBMS as-is, and things appeared to work.
Everything would stop instantly if you were to say enable quoting of
identifiers on your storage.

What you wanted to do is tell DBIC that the above is a literal SQL chunk
which must be transported to the RDBMS intact. This is done by supplying
a reference to the chunk in question:

    select => [ \"date_part('year', created)" ],

Cheers



More information about the DBIx-Class mailing list