Re: INSERT WHERE NOT EXISTS - Mailing list pgsql-general

From Lincoln Yeoh
Subject Re: INSERT WHERE NOT EXISTS
Date
Msg-id 5.2.1.1.1.20030628114112.02ec7d50@mbox.jaring.my
Whole thread Raw
In response to Re: INSERT WHERE NOT EXISTS  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Responses Re: INSERT WHERE NOT EXISTS  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
At 01:36 AM 6/28/2003 +0200, Karsten Hilbert wrote:

>Because
>
> >>select exists(select * from tablename where [cond])
>
>will return after finding 1 matching row (or am I
>wrong ?) while
>
> > SELECT 1 FROM tablename WHERE [cond];
>
>will return a 1 for *each* matching row (just tested).

You can use limit. Postgresql is smart enough to stop once it has the
necessary rows[1].

select 1 from table name where cond limit 1;

Link.

[1] Or was it necessary rows + 1? Agh, something wrong with my memory.

pgsql-general by date:

Previous
From: Ron Johnson
Date:
Subject: Re: Redhat's "enhancements" to PG
Next
From: Tom Lane
Date:
Subject: Re: Redhat's "enhancements" to PG