Re: BOOLEAN question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: josh(at)agliodbs(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: BOOLEAN question
Date: 2002-10-29 18:27:34
Message-ID: 22789.1035916054@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Josh Berkus <josh(at)agliodbs(dot)com> writes:
> Odd question: I have a query that returns a set of none to several rows. One
> column in these rows is BOOLEAN. I want the query to return:
> 1) TRUE if *any* of the BOOLEAN values is TRUE;
> 2) FALSE if *all* of the BOOLEAN values are FALSE;
> 3) FALSE or NULL if no rows are returned.

Perhaps
SELECT true = ANY (SELECT boolcol FROM ...);
or
SELECT true IN (SELECT boolcol FROM ...);

Which is not to say that MAX(bool) might not be a nicer solution;
but you can definitely do it with SQL-spec constructs.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2002-10-29 18:36:17 Re: [SQL] Creating Stored Procedures
Previous Message Philip Van Hoof 2002-10-29 18:23:41 Creating Stored Procedures