Re: create constant values - Mailing list pgsql-novice

From Michael Glaesemann
Subject Re: create constant values
Date
Msg-id 58DFC5B9-9A25-417F-AC82-F7C13C172AC1@seespotcode.net
Whole thread Raw
In response to Re: create constant values  (john@msasystems.net)
List pgsql-novice
On Nov 21, 2007, at 13:16 , john@msasystems.net wrote:

> Hi,
>
>    i have a:
>                      select * from foo where type = 1 and score > 12;
>
>    i would like to say
>
>                      select * from foo where type = QUARTERBACK and
> score > 12;

You should have a table which enumerates your types, so you can do
something like:

SELECT *
   FROM foo
   JOIN foo_types USING (type)
   WHERE foo_types.type = 'quarterback'
       AND score > 12;

Magic numbers in a database (or anywhere else for that matter) is not
a good idea.

(Or use the enum types in 8.3, currently beta3)

Michael Glaesemann
grzm seespotcode net



pgsql-novice by date:

Previous
From: chrisj
Date:
Subject: Re: [OT] Installing 8.3beta on debian (stable)
Next
From: Dean Rasheed
Date:
Subject: A question of volatility