X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 11C2E3CC8C0 for ; Fri, 17 Dec 2004 12:43:15 +0000 (GMT) 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 43829-01 for ; Fri, 17 Dec 2004 12:43:09 +0000 (GMT) Received: from druid.net (druid.net [216.126.72.98]) by svr1.postgresql.org (Postfix) with ESMTP id DC9013CC888 for ; Fri, 17 Dec 2004 12:43:11 +0000 (GMT) Received: from imp.druid.net (imp [216.126.72.111]) by druid.net (Postfix) with SMTP id 214271A81; Fri, 17 Dec 2004 07:43:13 -0500 (EST) Date: Fri, 17 Dec 2004 07:42:57 -0500 From: "D'Arcy J.M. Cain" To: Kenneth Gonsalves Cc: pgsql-sql@postgresql.org Subject: Re: sql can i substitute Message-Id: <20041217074257.42a44460.darcy@druid.net> In-Reply-To: <0412171655451H.06834@thenilgiris.com> References: <0412171655451H.06834@thenilgiris.com> X-Mailer: Sylpheed version 1.0.0beta3 (GTK+ 1.2.10; i386--netbsdelf) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.279 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200412/120 X-Sequence-Number: 19740 On Fri, 17 Dec 2004 16:55:45 +0530 Kenneth Gonsalves wrote: > i want to write an sql statement like this: > > select fruit from table > > which should return 'good' if fruit = 1 and 'bad' if fruit =2 and > 'rotten' if fruit =3 An alternative to Andreas' suggestion would be to create a simple lookup table and join them. This is good if the real life example can get larger and/or the list can change and you don't want to modify code every time it does. [totally made up output] fstate_id | fstate_name ----------+------------- 1 | good 2 | bad 3 | rotten SELECT fstate.fstate_name AS "Fruit state" FROM table, fstate WHERE table.fstate_id = fstate.fstate_id; Now you can easily add another state: INSERT INTO fstate VALUES (4, 'smelly'); -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.