X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 2E7CC52B7E for ; Thu, 18 Aug 2005 22:54:04 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 08836-10 for ; Fri, 19 Aug 2005 01:54:01 +0000 (GMT) Received: from mail.aveo.aveopharma.com (67.109.105.227.ptr.us.xo.net [67.109.105.227]) by svr1.postgresql.org (Postfix) with SMTP id 9316952B6A for ; Thu, 18 Aug 2005 22:53:59 -0300 (ADT) X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Re: SQL CASE Statements Date: Thu, 18 Aug 2005 21:56:17 -0400 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [SQL] SQL CASE Statements Thread-Index: AcWkXtQK1nB0whU8Ru+ufNv68L/d1wAAQU4Q From: "Dmitri Bichko" To: "Lane Van Ingen" , X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.074 required=5 tests=[AWL=0.024, FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200508/155 X-Sequence-Number: 22383 I am not sure what you are asking... SELECT CASE WHEN EXISTS (SELECT foo FROM bar WHERE baz =3D 'a') THEN 1 ELSE 0 END; Or SELECT CASE WHEN 'a' =3D ANY (SELECT froo FROM bar) THEN 1 ELSE 0 END; Both work, but that's pretty much what you had already - am I missing what you are trying to achieve? Though both are likely to be quite inefficient if you are looking up many values. Maybe something like: SELECT f.a, CASE WHEN b.a IS NOT NULL THEN 1 ELSE 0 END FROM foo f LEFT JOIN bar b USING (a) Assuming "foo" has the values you want to look up, and "bar" is the table you check for existence. Dmitri > -----Original Message----- > From: pgsql-sql-owner@postgresql.org=20 > [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Lane Van Ingen > Sent: Thursday, August 18, 2005 9:32 PM > To: pgsql-sql@postgresql.org > Subject: [SQL] SQL CASE Statements >=20 >=20 > In the following CASE statement, is it possible to put a=20 > SELECT ... WHERE EXISTS in the of a CASE=20 > statement, and have it work? >=20 > The I want to do is to yield a result of '1' if=20 > the statement finds the value 'a' in a table (EXISTS=20 > evaluates true), and '0' if it evaluates false ('a' not found). >=20 > SELECT a, > CASE WHEN THEN 1 > ELSE 0 > END >=20 > Has anybody done this? If so, can you send me a sample? >=20 >=20 >=20 > ---------------------------(end of=20 > broadcast)--------------------------- > TIP 4: Have you searched our list archives? >=20 http://archives.postgresql.org The information transmitted is intended only for the person or entity to = which it is addressed and may contain confidential and/or privileged mate= rial. Any review, retransmission, dissemination or other use of, or takin= g of any action in reliance upon, this information by persons or entities= other than the intended recipient is prohibited. If you received this in= error, please contact the sender and delete the material from any comput= er