Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 914C047668A for ; Tue, 29 Oct 2002 13:27:43 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id D9F39476683 for ; Tue, 29 Oct 2002 13:27:42 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.5/8.12.5) with ESMTP id g9TIRYhR022790; Tue, 29 Oct 2002 13:27:34 -0500 (EST) To: josh@agliodbs.com Cc: pgsql-sql@postgresql.org Subject: Re: BOOLEAN question In-reply-to: <200210281706.39015.josh@agliodbs.com> References: <200210281706.39015.josh@agliodbs.com> Comments: In-reply-to Josh Berkus message dated "Mon, 28 Oct 2002 18:06:39 -0700" Date: Tue, 29 Oct 2002 13:27:34 -0500 Message-ID: <22789.1035916054@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/390 X-Sequence-Number: 10107 Josh Berkus 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