From andreas.dafferner at adw.uni-heidelberg.de Thu Mar 8 06:52:01 2018 From: andreas.dafferner at adw.uni-heidelberg.de (Andreas Dafferner) Date: Thu, 8 Mar 2018 07:52:01 +0100 Subject: [Dbix-class] Newbie from SQL to DBIx Message-ID: <04235a38-5cf5-5d10-8032-ff9f4731dd36@adw.uni-heidelberg.de> I'm quite new to DBIx and cannot find out what is the DBIx way for select distinct left (col, (length(col) - 9)) from table order by col ??? Thank you for any help Andreas From billcrawford1970 at gmail.com Thu Mar 8 10:12:59 2018 From: billcrawford1970 at gmail.com (Will Crawford) Date: Thu, 8 Mar 2018 10:12:59 +0000 Subject: [Dbix-class] Newbie from SQL to DBIx In-Reply-To: <04235a38-5cf5-5d10-8032-ff9f4731dd36@adw.uni-heidelberg.de> References: <04235a38-5cf5-5d10-8032-ff9f4731dd36@adw.uni-heidelberg.de> Message-ID: A visit to https://www.google.co.uk/search?q=dbix+select+distinct should answer your question: DBIx::Class::Manual::Cookbook (first result here) says: SELECT DISTINCT with multiple columns ... my $rs = $schema->resultset('Artist')->search( {}, { columns => [ qw/artist_id name rank/ ], distinct => 1 } ); ... It *is* a little hard to find, I guess, since the word "distinct" does not appear in DBIx::Class::Manual::Features, and the explanation of *distinct* in DBIx::Class::ResultSet only mentions `GROUP BY`. You can generate the functional form by writing e.g. { ..., columns => [ { distinct => ... } ] }; On 8 March 2018 at 06:52, Andreas Dafferner < andreas.dafferner at adw.uni-heidelberg.de> wrote: > I'm quite new to DBIx and cannot find out what is the DBIx way for > > select distinct left (col, (length(col) - 9)) from table order by col > > ??? > > Thank you for any help > > Andreas > > _______________________________________________ > List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class > IRC: irc.perl.org#dbix-class > SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ > Searchable Archive: http://www.grokbase.com/group/ > dbix-class at lists.scsys.co.uk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreas.dafferner at adw.uni-heidelberg.de Thu Mar 8 11:40:26 2018 From: andreas.dafferner at adw.uni-heidelberg.de (Andreas Dafferner) Date: Thu, 8 Mar 2018 12:40:26 +0100 Subject: [Dbix-class] Newbie from SQL to DBIx In-Reply-To: References: <04235a38-5cf5-5d10-8032-ff9f4731dd36@adw.uni-heidelberg.de> Message-ID: Am 08.03.2018 um 11:12 schrieb Will Crawford: > It *is* a little hard to find, I guess, since the word "distinct" does > not appear in?DBIx::Class::Manual::Features, and the explanation of > *distinct* in DBIx::Class::ResultSet only mentions `GROUP BY`. the main problem is the part with left (col, (length(col) - 9) Andreas From matthew at mysociety.org Thu Mar 8 11:56:46 2018 From: matthew at mysociety.org (Matthew Somerville) Date: Thu, 8 Mar 2018 11:56:46 +0000 Subject: [Dbix-class] Newbie from SQL to DBIx In-Reply-To: <04235a38-5cf5-5d10-8032-ff9f4731dd36@adw.uni-heidelberg.de> References: <04235a38-5cf5-5d10-8032-ff9f4731dd36@adw.uni-heidelberg.de> Message-ID: On 8 March 2018 at 06:52, Andreas Dafferner wrote: > select distinct left (col, (length(col) - 9)) from table order by col You could do this: FixMyStreet::DB->resultset("Table")->search({}, { columns => { col => \"left(col, length(col)-9)" }, distinct => 1, order_by => "left(col, length(col)-9)" }); Run with DBIC_TRACE, the SQL for this is: SELECT left(col, length(col)-9) FROM table me GROUP BY left(col, length(col)-9) ORDER BY left(col, length(col)-9): And the resultant column is available as ->col for each row. ATB, Matthew From andreas.dafferner at adw.uni-heidelberg.de Thu Mar 8 12:18:53 2018 From: andreas.dafferner at adw.uni-heidelberg.de (Andreas Dafferner) Date: Thu, 8 Mar 2018 13:18:53 +0100 Subject: [Dbix-class] Newbie from SQL to DBIx In-Reply-To: References: <04235a38-5cf5-5d10-8032-ff9f4731dd36@adw.uni-heidelberg.de> Message-ID: Am 08.03.2018 um 12:56 schrieb Matthew Somerville: > You could do this: > > FixMyStreet::DB->resultset("Table")->search({}, { > columns => { col => \"left(col, length(col)-9)" }, > distinct => 1, > order_by => "left(col, length(col)-9)" }); Thank you VERY much!!! Andreas