Skip site navigation (1) Skip section navigation (2)

Re: NEWBEE: 'WHERE true' question

From: GH <grasshacker(at)over-yonder(dot)net>
To:
Cc: PGSQL Novice List <pgsql-novice(at)postgresql(dot)org>
Subject: Re: NEWBEE: 'WHERE true' question
Date: 2000-11-16 04:36:58
Message-ID: 20001115223658.A13873@over-yonder.net (view raw or flat)
Thread:
Lists: pgsql-novice
On Wed, Nov 15, 2000 at 09:16:37PM -0700, some SMTP stream spewed forth: 
> Hello,
> 
*snip*
> A snippet from this code is as follows:
> 
> ...
>   $where = 'true';
>   if ($form->{number}) {
>     $callback .= "&number=$form->{number}";
>     $where .= " AND number ~* '$form->{number}'";
>   }
>   if ($form->{description}) {  
>     $callback .= "&description=$form->{description}";
>     $where .= " AND description ~* '$form->{description}'";
>   }
> 
>   $query = qq|SELECT id, number, description, onhand, unit, sellprice
>                 FROM parts
>                 WHERE $where
>                 ORDER BY $form->{sort}
>              |;
> ...
> 
> Now if the two 'if' conditionals are false, the query becomes:
> 
> SELECT id, number, description, onhand, unit, sellprice
>                 FROM parts
>                 WHERE true
>                 ORDER BY number
> 
> 
> What does it mean here for the WHERE to be true?  What is being tested
> for true?  Is this just a 'place holder', if you will, for the WHERE
> field in case the two 'if' conditionals are false and so the WHERE field
> is not blank?
> 

Er, I hope this helps.
< http://www.postgresql.org/docs/user/sql-select.htm#SQL-WHERE >

It looks like the 'true' is just in there to ensure that all rows are
returned.
I can't think of why someone wolud do that..


G'luck and 
cheers
gh

> Thanks,
> Murrah Boswell
> 

In response to

pgsql-novice by date

Next:From: Tom LaneDate: 2000-11-16 04:44:44
Subject: Re: Granting Browser Access to pgsql database.
Previous:From: OTR CommDate: 2000-11-16 04:16:37
Subject: NEWBEE: 'WHERE true' question

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group