X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 63B539FA621 for ; Thu, 8 Jun 2006 12:50:52 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 69913-08 for ; Thu, 8 Jun 2006 12:50:43 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from srv2.worldnox.net (srv2.worldnox.net [204.10.36.240]) by postgresql.org (Postfix) with ESMTP id E02829F9EF3 for ; Thu, 8 Jun 2006 12:50:43 -0300 (ADT) Received: from nat-ip.dynetics.com ([204.154.192.252] helo=[10.1.16.24]) by srv2.worldnox.net with esmtpa (Exim 4.52) id 1FoMmR-0000SX-La; Thu, 08 Jun 2006 11:50:43 -0400 Message-ID: <44884752.7030303@dafunks.com> Date: Thu, 08 Jun 2006 10:50:42 -0500 From: George Handin User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 To: Richard Broersma Jr CC: pgsql-sql@postgresql.org Subject: Re: Query to return modified results at runtime? References: <20060608043236.96435.qmail@web31810.mail.mud.yahoo.com> In-Reply-To: <20060608043236.96435.qmail@web31810.mail.mud.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - srv2.worldnox.net X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [47 12] X-AntiAbuse: Sender Address Domain - dafunks.com X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/95 X-Sequence-Number: 25331 Richard Broersma Jr wrote: >> ID Color >> --- ------- >> 1 Blue >> 2 Red >> 3 Green >> 4 Orange >> >> How would I rewrite the query to return results where the colors are >> replaced by letters to give the following results? >> >> ID Color >> --- ------- >> 1 A >> 2 D >> 3 B >> 4 C > > > http://www.postgresql.org/docs/8.1/interactive/functions-conditional.html > > this is probably the easiest to implement but hard to mangage over time. Another solution would > be to create color_code table that is referenced by your test table. Then when you can create a > query as: select a.ID, b.code from test as a join color_code as b on a.color = b.color; > > There are additional solutions to this also. But these two are probably the easiest. Thanks!