[Dbix-class] Union and Limit

Peter Rabbitson rabbit+dbic at rabbit.us
Wed Feb 9 07:32:43 GMT 2011


Mike Raynham wrote:
> Hi,
> 
> I am using union from DBIx::Class::Helper::ResultSet::SetOperations, but 
> am struggling a little with the syntax.  I'm hoping that someone can help.
> 
> I have three individual queries that need to be returned, and the rows 
> from each SELECT are to be returned one after the other.  The DBMS is 
> MySQL, and I need to structure the query as per the examples shown at 
> the end of this page:
> 
> http://dev.mysql.com/doc/refman/5.1/en/union.html
> 
> I have used the '+as' attribute so that I may easily identify the rows 
> from each SELECT via 'get_column'.
> 
> I also need to place a LIMIT on the last two queries, and this is where 
> I am having difficulty.  My code is as follows:
> 
> 
> The problem I have encountered is that the individual SELECT statements 
> are not enclosed in parentheses, so LIMIT is being applied to the 
> overall result, and not the individual SELECTs.  The SQL from the above 
> code is:
> 
> Is it a 'feature' of MySQL that it requires the additional parentheses? 
>  Is there a way for me to add the parentheses to my search?
> 

Yes. http://search.cpan.org/~abraxxa/DBIx-Class-0.08127/lib/DBIx/Class/ResultSet.pm#as_subselect_rs



More information about the DBIx-Class mailing list