[Dbix-class] Nested Selects and Getting SQL from Resultset

Jess Robinson castaway at desert-island.me.uk
Fri Oct 24 16:10:07 BST 2008


On Fri, 24 Oct 2008, Howe, Tom (IT) wrote:

> I'm trying to do the following
>
>
> i have a table with 3 columns.... col1, col2 & time
>
> I want to create some methods that I can pass dbix resultsets into that will generate new tables
>
> the first byMin takes the time field and blanks out the seconds, generating a new column called 'minutes'
>
> the second method is designed to take the output from the first resultset and group by the newly formed minutes column.
>
> However it doesnt work - it complains that minutes does not exist.
>
> So its obviously not attempting to generate a nested select for me.
>
> Is there anyway to do this?
>
>
> sub byMin {
>  my $rs = shift;
>  $rs->search ( {} , { select => [ 'col1', 'col2', 'strftime("%H%M:00", time)' ], as => ['col1', 'col2', 'minutes']  } );
> }
>
> sub byMinGrouped {
>  my $rs = byMin(shift);
>  $rs->search ( {} , { select => [ 'col1', 'minutes' ], as => ['col1', 'minutes'], group_by => ['col1', 'minutes']  } );
> }

Yes, See DBIx::Class::Manual::FAQ, the section about using "AS" in the 
queries.


Next time please create a new email instead of replying to an old one, as 
threaded email clients display your new question at the bottom of a long 
and possibly ignored thread of another question. Thanks!

Jess




More information about the DBIx-Class mailing list