Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: create constant values




On Nov 21, 2007, at 13:16 , john(at)msasystems(dot)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





Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group