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 100B39FA5BA for ; Thu, 8 Jun 2006 01:32:42 -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 35974-10 for ; Thu, 8 Jun 2006 01:32:38 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web31810.mail.mud.yahoo.com (web31810.mail.mud.yahoo.com [68.142.207.73]) by postgresql.org (Postfix) with SMTP id 118919FA3CD for ; Thu, 8 Jun 2006 01:32:37 -0300 (ADT) Received: (qmail 96437 invoked by uid 60001); 8 Jun 2006 04:32:36 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=JtOSCibJqdE4PxXC1jgoHQgoyAcHsKx/h6e5MrBYfw8mHhsFvo7mIgUnKcItoRywLAFWhznsn0EqwyL+t80UQv2cYSKpQAQnXYfLquVIRGTao84anZM/blKnypbHB4heY+zCxP0hSARks6YPGIb2h0OILSQ+m2c87P3RZY4s0VM= ; Message-ID: <20060608043236.96435.qmail@web31810.mail.mud.yahoo.com> Received: from [68.235.218.116] by web31810.mail.mud.yahoo.com via HTTP; Wed, 07 Jun 2006 21:32:36 PDT Date: Wed, 7 Jun 2006 21:32:36 -0700 (PDT) From: Richard Broersma Jr Subject: Re: Query to return modified results at runtime? To: George Handin , pgsql-sql@postgresql.org In-Reply-To: <44876F63.9030302@dafunks.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/93 X-Sequence-Number: 25329 > 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.