pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Broersma Jr <rabroersma@yahoo.com>
To: George Handin <postgresql@dafunks.com>
To: pgsql-sql@postgresql.org
Subject: Re: Query to return modified results at runtime?
Date: Wed, 7 Jun 2006 21:32:36 -0700 (PDT)
Message-ID: <20060608043236.96435.qmail@web31810.mail.mud.yahoo.com> (raw)
In-Reply-To: <44876F63.9030302@dafunks.com>

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



view thread (5+ messages)  latest in thread

Message-ID: <20060608043236.96435.qmail@web31810.mail.mud.yahoo.com>
Permalink:  ../20060608043236.96435.qmail@web31810.mail.mud.yahoo.com/
Also on:    postgresql.org/message-id/20060608043236.96435.qmail@web31810.mail.mud.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: rabroersma@yahoo.com, postgresql@dafunks.com
  Subject: Re: Query to return modified results at runtime?
  In-Reply-To: <20060608043236.96435.qmail@web31810.mail.mud.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox