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 310AED6E91 for ; Mon, 22 Aug 2005 10:46:17 -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 10254-03 for ; Mon, 22 Aug 2005 13:46:15 +0000 (GMT) Received: from TWMAIL.ESNCC.COM (static-66-173-159-28.t1.cavtel.net [66.173.159.28]) by svr1.postgresql.org (Postfix) with ESMTP id 6EB05D6E73 for ; Mon, 22 Aug 2005 10:46:09 -0300 (ADT) Received: from spawar2i8uvlb9 ([150.125.117.63]) by TWMAIL.ESNCC.COM with Microsoft SMTPSVC(5.0.2195.6713); Mon, 22 Aug 2005 09:46:12 -0400 From: "Lane Van Ingen" To: "Halley Pacheco de Oliveira" , Subject: Re: SQL CASE Statements Date: Mon, 22 Aug 2005 09:42:49 -0400 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) In-Reply-To: <20050820112516.43689.qmail@web52714.mail.yahoo.com> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.181 Importance: Normal X-OriginalArrivalTime: 22 Aug 2005 13:46:12.0532 (UTC) FILETIME=[DBEA5740:01C5A71F] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.079 required=5 tests=[AWL=0.029, FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200508/183 X-Sequence-Number: 22411 Halley, here is a sample for you that might help; the purpose of this function was to set an indicator of '1' or '0' (true or false) on a router interface if the router interface ID was the same as the default gateway for the Router node ID: create view current_default_gateways_v (router_id, default_gateway) AS select router_id, case when router_id in (select interface_id from router_interface ri, network_nodes nn where ri.node_id = nn.node_id and ri.interface_id = nn.default_gateway_interface_id) then 1 else 0 end as if_default_gateway from router_interface; TABLES USED: network_nodes: node_id, serial node_name, varchar default_gateway_interface_id, integer router_interfaces: interface_id, serial (integer) node_id (FK) -----Original Message----- From: Halley Pacheco de Oliveira [mailto:halleypo@yahoo.com.br] Sent: Saturday, August 20, 2005 7:25 AM To: pgsql-sql@postgresql.org Cc: lvaningen@esncc.com Subject: RE: SQL CASE Statements > Has anybody done this? If so, can you send me a sample? CREATE TEMPORARY TABLE fruits (id SERIAL, name TEXT); INSERT INTO fruits VALUES (DEFAULT, 'banana'); INSERT INTO fruits VALUES (DEFAULT, 'apple'); CREATE TEMPORARY TABLE food (id SERIAL, name TEXT); INSERT INTO food VALUES (DEFAULT, 'apple'); INSERT INTO food VALUES (DEFAULT, 'spinach'); SELECT name, CASE WHEN name = ANY (SELECT name FROM fruits) THEN 'yes' ELSE 'no' END AS fruit FROM food; name | fruit ---------+------- apple | yes spinach | no (2 lines) __________________________________________________ Converse com seus amigos em tempo real com o Yahoo! Messenger http://br.download.yahoo.com/messenger/