pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
setting the where clause
4+ messages / 4 participants
[nested] [flat]

* setting the where clause
@ 2009-06-10 12:19  johnf <jfabiani@yolo.com>
  0 siblings, 2 replies; 4+ messages in thread

From: johnf @ 2009-06-10 12:19 UTC (permalink / raw)
  To: pgsql-sql

Hi,
I'm am programming in python using the Dabo modules.  www.dabodev.com if your 
interested.  Dabo is a framework that provides an easy way to build desktop 
app's.  To clear a data entry form. I have been setting the where clause 
to "where 1=0".  This of course retrieves 0 records and my form will display 
nothing.  It has been suggested that it might be better to set the where 
clause to a primary key value that does not exist in the table  "where PK 
= -9999999".   

I wonder what you guys think.  How might it effect performance?
-- 
John Fabiani



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: setting the where clause
@ 2009-06-10 14:19  Tom Lane <tgl@sss.pgh.pa.us>
  parent: johnf <jfabiani@yolo.com>
  1 sibling, 1 reply; 4+ messages in thread

From: Tom Lane @ 2009-06-10 14:19 UTC (permalink / raw)
  To: johnf <jfabiani@yolo.com>; +Cc: pgsql-sql

johnf <jfabiani@yolo.com> writes:
> I'm am programming in python using the Dabo modules.  www.dabodev.com if your 
> interested.  Dabo is a framework that provides an easy way to build desktop 
> app's.  To clear a data entry form. I have been setting the where clause 
> to "where 1=0".  This of course retrieves 0 records and my form will display 
> nothing.  It has been suggested that it might be better to set the where 
> clause to a primary key value that does not exist in the table  "where PK 
> = -9999999".   

Whoever said that doesn't know what they're talking about.  It's not
faster (because it forces an actual index probe to happen) and it's not
safer (what if one day that PK value exists?).

I'd personally go with "where false"; why not say what you mean rather
than forcing humans and computers to deduce that the condition is
constant false?

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: setting the where clause
@ 2009-06-10 15:13  Rob Sargent <robjsargent@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Rob Sargent @ 2009-06-10 15:13 UTC (permalink / raw)
  To: pgsql-sql


Tom Lane wrote:
> johnf <jfabiani@yolo.com> writes:
>   
>> I'm am programming in python using the Dabo modules.  www.dabodev.com if your 
>> interested.  Dabo is a framework that provides an easy way to build desktop 
>> app's.  To clear a data entry form. I have been setting the where clause 
>> to "where 1=0".  This of course retrieves 0 records and my form will display 
>> nothing.  It has been suggested that it might be better to set the where 
>> clause to a primary key value that does not exist in the table  "where PK 
>> = -9999999".   
>>     
>
> Whoever said that doesn't know what they're talking about.  It's not
> faster (because it forces an actual index probe to happen) and it's not
> safer (what if one day that PK value exists?).
>
> I'd personally go with "where false"; why not say what you mean rather
> than forcing humans and computers to deduce that the condition is
> constant false?
>
> 			regards, tom lane
>
>   

Of course you would do the world a favour if you wrote a client-side 
clear-the-screen routine that didn't pester the net and the server 
un-necessarily.



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: setting the where clause
@ 2009-06-12 12:33  Jasen Betts <jasen@xnet.co.nz>
  parent: johnf <jfabiani@yolo.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Jasen Betts @ 2009-06-12 12:33 UTC (permalink / raw)
  To: pgsql-sql

On 2009-06-10, johnf <jfabiani@yolo.com> wrote:
> Hi,
> I'm am programming in python using the Dabo modules.  www.dabodev.com if your 
> interested.  Dabo is a framework that provides an easy way to build desktop 
> app's.  To clear a data entry form. I have been setting the where clause 
> to "where 1=0".  This of course retrieves 0 records and my form will display 
> nothing.  It has been suggested that it might be better to set the where 
> clause to a primary key value that does not exist in the table  "where PK 
>= -9999999".   

"where PK=NULL" is better as anything=NULL is never true. PK=-9999999
may be true sometimes.

As Tom says  PK=-9999999  causes postgres to look for a record that
matches, PK=NULL doesn't cause needless search.

that said if -9999999 is outside of the valid range for PK then the
search will finish very quickly as at worst only a sigle btree page
will need to be loaded.

in order of preference.

  no query at all
  where FALSE
  where PK=NULL
  where PK=-9999999 (note that this one may not work)
  



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2009-06-12 12:33 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-06-10 12:19 setting the where clause johnf <jfabiani@yolo.com>
2009-06-10 14:19 ` Tom Lane <tgl@sss.pgh.pa.us>
2009-06-10 15:13   ` Rob Sargent <robjsargent@gmail.com>
2009-06-12 12:33 ` Jasen Betts <jasen@xnet.co.nz>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox