Re: aggregate functions, COUNT

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Kevin Way <kevin(dot)way(at)overtone(dot)org>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: aggregate functions, COUNT
Date: 2001-10-02 16:47:00
Message-ID: Pine.BSF.4.21.0110020944100.46517-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, 2 Oct 2001, Kevin Way wrote:

> I'm currently using a SELECT count(*) when all I really want to know is
> if 1 or more records exist. Is there a standard way to just find out if
> a record exists? If not, is there a way to avoid iterating over all the
> records by writing an aggregate function? Given what I've read of how
> they work, I don't see how to make the function return before parsing
> all the results anyway, am I wrong here?

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.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2001-10-02 16:47:09 Indexing behavior
Previous Message Stephan Szabo 2001-10-02 16:32:33 Re: Question about indexing!