Re: SQL CASE Statements

From: Halley Pacheco de Oliveira <halleypo(at)yahoo(dot)com(dot)br>
To: pgsql-sql(at)postgresql(dot)org
Cc: lvaningen(at)esncc(dot)com
Subject: Re: SQL CASE Statements
Date: 2005-08-20 11:25:16
Message-ID: 20050820112516.43689.qmail@web52714.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> 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/

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Moritz Bayer 2005-08-20 14:54:22 Problem with self-made plpgsql-function / casting
Previous Message Bruno Wolff III 2005-08-19 14:59:35 Re: PGSQL function for converting between arbitrary numeric bases?