Re: how to constrain a query to return 1 or 0 rows (or >1 or 0 rows)

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Kevin Murphy <murphy(at)genome(dot)chop(dot)edu>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: how to constrain a query to return 1 or 0 rows (or >1 or 0 rows)
Date: 2004-09-11 01:56:20
Message-ID: 20040911015620.GB9447@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Sep 10, 2004 at 17:39:31 -0400,
Kevin Murphy <murphy(at)genome(dot)chop(dot)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;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-09-11 02:12:53 Re: 8.0.0beta2: gcc: unrecognized option `-pthreads'
Previous Message Bruno Wolff III 2004-09-11 01:32:54 Re: Obtaining the Julian Day from a date