Grokbase
Topics Posts Groups | in
x
[ help ]

[Dbix-class] How to search records with "IS NOT NULL"

View TopicPrint | Flat  Thread  Threaded
1) Ramprabhu Kaliaperumal Hi All I want something like 'SELECT * FROM employee WHERE department IS NOT NULL' I tried...
| +1 vote (Anchor)
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
Hi All

I want something like 'SELECT * FROM employee WHERE department IS NOT NULL'

I tried $schema->resultset('employee')->search({ department => {"IS" =>
"NOT NULL"}});

But it is not working...

Any help?

Thanks
-Ram
2) Matt S Trout SQL::Abstract and DBIx::Class both treat undef as NULL. Just pass => { '!=', undef } and it'll do...
| +1 vote (Anchor)
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
On Tue, Jul 24, 2007 at 10:15:51PM +0530, Ramprabhu Kaliaperumal wrote:
> Hi All
>
> I want something like 'SELECT * FROM employee WHERE department IS NOT NULL'
>
> I tried $schema->resultset('employee')->search({ department => {"IS" =>
> "NOT NULL"}});

SQL::Abstract and DBIx::Class both treat undef as NULL. Just pass

=> { '!=', undef }

and it'll do the right thing.

--
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director    Want a managed development or deployment platform?
 Shadowcat Systems Ltd.  Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/ http://www.shadowcatsystems.co.uk/

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/dbix-class@lists.rawmode.org/
3) Fernan Aguero | Hi All | I want something like 'SELECT * FROM employee WHERE department IS NOT NULL' | I tried...
| +1 vote (Anchor)
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
|  Hi All
|
|  I want something like 'SELECT * FROM employee WHERE department IS NOT NULL'
|
| I tried $schema->resultset('employee')->search({ department => {"IS" => "NOT
|  NULL"}});
|
|  But it is not working...
|
|  Any help?
|

$rs->search( { department => { '!=', undef } } );

or

my $sql = 'IS NOT NULL';
$rs->search( { department => \$sql } )

Read the docs for SQL::Abstract
http://search.cpan.org/~nwiger/SQL-Abstract-1.22/lib/SQL/Abstract.pm

Fernan
4) Jason Thaxter Any suggestions on how to use the overlaps operator? Using Postgresql.. I read the SQL::Abstract...
| +1 vote (Anchor)
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
Any suggestions on how to use the overlaps operator? Using Postgresql..

I read the SQL::Abstract page after bottoming out on:
Cannot mix placeholder styles ":foo" and "?"

I found this in the docs:

    my %where  = (
        user   => 'nwiger',
        completion_date => {
           -not_between => ['2002-10-01', '2003-02-06']
        }
    );

    Would give you:

    WHERE user = ? AND completion_date NOT BETWEEN ( ? AND ? )


But it doesn't seem to recognize OVERLAPS the same way as BETWEEN:

    (start_time,end_time)" => { -overlaps => [$pg_alpha, $pg_omega] }

generates:

    WHERE ( ( ( (start_time,end_time) OVERLAPS $1 ) OR ( ...

Of course what I want is
    WHERE ( ( ( ( start_time,end_time) OVERLAPS (?, ?)

I could simulate overlaps with some OR clauses, but I made a mistake with that
before, so I'd rather use the proper SQL function.


--
----------------------------------------------
Jason Thaxter                           GoMOOS
        350 Commercial Street, Suite 308
              Portland, ME 0410
            Office: 207.773.0423
             Tel: 207.228.1665
          Email: [email protected: th...@gomoos.org]
----------------www.gomoos.org----------------

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/dbix-class@lists.rawmode.org/
spacer
View TopicPrint | Flat  Thread  Threaded
Home > Groups > DBIx::Class > [Dbix-class] How to search records with "IS NOT NULL" (4 posts)