Re: Declaring constants in SQL - Mailing list pgsql-general

From Richard Broersma
Subject Re: Declaring constants in SQL
Date
Msg-id 396486430807301353v69f08653t128ca7602da1bbd9@mail.gmail.com
Whole thread Raw
In response to Declaring constants in SQL  ("EXT-Rothermel, Peter M" <Peter.M.Rothermel@boeing.com>)
List pgsql-general
On Wed, Jul 30, 2008 at 1:16 PM, EXT-Rothermel, Peter M
<Peter.M.Rothermel@boeing.com> wrote:

> Is there any means like (#define or DECLARE ) where I can write SQL like
> this:
> CREATE VIEW primary_colors_foos AS
>   SELECT * from foo WHERE ( color = FOO_COLOR_RED OR color =
> FOO_COLOR_BLUE OR color = FOO_COLOR_YELLOW );

I don't think that you can declare SQL variables like this.  The
conventional method would be to use a look up table that hold the
cross-reference between integer and color name.  You could then change
your view definitional like so:

CREATE VIEW primary_colors_foos AS
  SELECT * FROM foo
   WHERE color = ANY( SELECT colorid
                        FROM Colors
                       WHERE colorname = ANY( 'red', 'blue', 'yellow' ));

--
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

pgsql-general by date:

Previous
From: "EXT-Rothermel, Peter M"
Date:
Subject: Declaring constants in SQL
Next
From: Rob Adams
Date:
Subject: archive_timeout, checkpoint_timeout