Re: aggregate functions, COUNT

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
Cc: Kevin Way <kevin(dot)way(at)overtone(dot)org>, pgsql-sql(at)postgresql(dot)org
Subject: Re: aggregate functions, COUNT
Date: 2001-10-02 17:59:26
Message-ID: 10539.1002045566@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> writes:
> I think you could use EXISTS for that,
> select EXISTS (<query>); should give a true/false on whether the
> query returned any rows. I'm not sure if it stops after one row
> or not, but if it doesn't you can add a limit 1 to the query.

Yes it does stop after one row; and furthermore, the planner knows to
generate a fast-start plan for it. (Or at least it's supposed to
... hmm, this seems to be broken in current sources ...) Anyway,
there's no need for LIMIT 1 inside an EXISTS, because the planner
assumes that automatically.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Jeong 2001-10-02 19:09:27 Re: Question about indexing!
Previous Message Josh Berkus 2001-10-02 16:47:09 Indexing behavior