NOT IN queries

7 messages Options
Embed this post
Permalink
Dermot

NOT IN queries

Reply Threaded More More options
Print post
Permalink
Hi,

I suspect the answer to the question, "can I use
DBIx::Class::Resultset to do a sql query like this":

SELECT * FROM countries where iso2letter NOT IN ('GB','IE', 'HK','US');

is  "use DBIx::SQL::Abstract".

Can someone confirm?
Thanx,
Dp.

_______________________________________________
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@...
Rob Kinyon

Re: NOT IN queries

Reply Threaded More More options
Print post
Permalink
On Thu, Oct 1, 2009 at 16:18, Dermot <[hidden email]> wrote:
> Hi,
>
> I suspect the answer to the question, "can I use
> DBIx::Class::Resultset to do a sql query like this":
>
> SELECT * FROM countries where iso2letter NOT IN ('GB','IE', 'HK','US');

$countries_rs->search({ iso2letter => { -not_in => [ 'GB', 'IE', 'HK',
'UK' ] } });

You'll need a reasonably new DBIx::Class.

--
Thanks,
Rob Kinyon

_______________________________________________
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@...
Cory Watson

Re: NOT IN queries

Reply Threaded More More options
Print post
Permalink
In reply to this post by Dermot
On Thu, Oct 1, 2009 at 3:18 PM, Dermot <[hidden email]> wrote:
> Hi,
>
> I suspect the answer to the question, "can I use
> DBIx::Class::Resultset to do a sql query like this":
>
> SELECT * FROM countries where iso2letter NOT IN ('GB','IE', 'HK','US');

Isn't it just:

->search({ iso2letter => { '-not-in' => [qw(GB IE HK US)] })

I'm throwing that out from memory...

--
Cory 'G' Watson
http://www.onemogin.com

_______________________________________________
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@...
Cory Watson

Re: NOT IN queries

Reply Threaded More More options
Print post
Permalink
On Thu, Oct 1, 2009 at 3:22 PM, Cory Watson <[hidden email]> wrote:

> On Thu, Oct 1, 2009 at 3:18 PM, Dermot <[hidden email]> wrote:
>> Hi,
>>
>> I suspect the answer to the question, "can I use
>> DBIx::Class::Resultset to do a sql query like this":
>>
>> SELECT * FROM countries where iso2letter NOT IN ('GB','IE', 'HK','US');
>
> Isn't it just:
>
> ->search({ iso2letter => { '-not-in' => [qw(GB IE HK US)] })

Er, Rob's response is right.  That's not_in. (underscore)

--
Cory 'G' Watson
http://www.onemogin.com

_______________________________________________
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@...
Dermot

Re: NOT IN queries

Reply Threaded More More options
Print post
Permalink
2009/10/1 Cory Watson <[hidden email]>:

> On Thu, Oct 1, 2009 at 3:22 PM, Cory Watson <[hidden email]> wrote:
>> On Thu, Oct 1, 2009 at 3:18 PM, Dermot <[hidden email]> wrote:
>>> Hi,
>>>
>>> I suspect the answer to the question, "can I use
>>> DBIx::Class::Resultset to do a sql query like this":
>>>
>>> SELECT * FROM countries where iso2letter NOT IN ('GB','IE', 'HK','US');
>>
>> Isn't it just:
>>
>> ->search({ iso2letter => { '-not-in' => [qw(GB IE HK US)] })

Thanx for putting me straight on that.

Is this construct within search() from SQL::Abstract?  I can't see it
within the DBIx::Class docs.

Dp.

_______________________________________________
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@...
Rob Kinyon

Re: NOT IN queries

Reply Threaded More More options
Print post
Permalink
On Thu, Oct 1, 2009 at 17:26, Dermot <[hidden email]> wrote:
> Thanx for putting me straight on that.
>
> Is this construct within search() from SQL::Abstract?  I can't see it
> within the DBIx::Class docs.

Yes, the first argument to search() gets passed (almost wholesale) to
SQL::Abstract.

_______________________________________________
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@...
Justin Hunter

Re: NOT IN queries

Reply Threaded More More options
Print post
Permalink
In reply to this post by Dermot
http://search.cpan.org/dist/SQL-Abstract/lib/SQL/Abstract.pm#Special_operators_:_IN,_BETWEEN,_etc.

Justin

On Thu, Oct 1, 2009 at 2:26 PM, Dermot <[hidden email]> wrote:
2009/10/1 Cory Watson <[hidden email]>:
> On Thu, Oct 1, 2009 at 3:22 PM, Cory Watson <[hidden email]> wrote:
>> On Thu, Oct 1, 2009 at 3:18 PM, Dermot <[hidden email]> wrote:
>>> Hi,
>>>
>>> I suspect the answer to the question, "can I use
>>> DBIx::Class::Resultset to do a sql query like this":
>>>
>>> SELECT * FROM countries where iso2letter NOT IN ('GB','IE', 'HK','US');
>>
>> Isn't it just:
>>
>> ->search({ iso2letter => { '-not-in' => [qw(GB IE HK US)] })

Thanx for putting me straight on that.

Is this construct within search() from SQL::Abstract?  I can't see it
within the DBIx::Class docs.

Dp.

_______________________________________________
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@...


_______________________________________________
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@...