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.