Re: how to constrain a query to return 1 or 0 rows (or >1 or 0 rows) - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: how to constrain a query to return 1 or 0 rows (or >1 or 0 rows)
Date
Msg-id 20040911015620.GB9447@wolff.to
Whole thread Raw
In response to how to constrain a query to return 1 or 0 rows (or >1 or 0 rows)  (Kevin Murphy <murphy@genome.chop.edu>)
List pgsql-general
On Fri, Sep 10, 2004 at 17:39:31 -0400,
  Kevin Murphy <murphy@genome.chop.edu> wrote:
> This is probably a stupid question, but ...
>
> I'd like to be able to take an existing query and modify it to return a
> single row if that's what the base query returns, and 0 rows if the
> base query returns multiple rows.  Similarly, I'd like to also modify
> it to return multiple rows if that's what the base query returns, and 0
> rows if the base query return a single row.
>
> What's a good way to do this?

SELECT * FROM whatever HAVING count(*) < 1;

pgsql-general by date:

Previous
From: Randy Yates
Date:
Subject: Re: Another Security Question: User-based Roles vs. Application
Next
From: Tom Lane
Date:
Subject: Re: 8.0.0beta2: gcc: unrecognized option `-pthreads'