Re: When does a check constraint execute? - Mailing list pgsql-general

From Jim C. Nasby
Subject Re: When does a check constraint execute?
Date
Msg-id 20060327115239.GX80726@pervasive.com
Whole thread Raw
In response to When does a check constraint execute?  (<Edmund.Bacon@elb_lx.onesystem.ca>, ebacon@onesystem.com)
Responses Re: Pet-peevishness (When does a check constraint execute?)  (Alban Hertroys <alban@magproductions.nl>)
List pgsql-general
On Fri, Mar 24, 2006 at 11:25:35AM -0700, Edmund.Bacon@elb_lx.onesystem.ca wrote:
> test-# $$ select not exists
> test$#     (select * from test_dates t1
> test$#       where 1 < ( select count(*) from test_dates t2
> test$#                   where (t1.from_date, t1.to_date) overlaps
> test$#                            (t2.from_date, t2.to_date)) )$$;

<pet-peeve>
If you only want to know if something exists, do NOT use count!

> test$#     (select * from test_dates t1
> test$#       where EXISTS ( select * from test_dates t2
> test$#                   where (t1.from_date, t1.to_date) overlaps
> test$#                            (t2.from_date, t2.to_date)) )$$;

On a small dataset you may not notice much difference, but you'll
certainly see it on a large dataset.
</pet-peeve>
--
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Converting a database from LATIN1 to UTF-8
Next
From: "Jim C. Nasby"
Date:
Subject: Re: PostgreSQL support on Redhat Advance Server 2.1