Re: Declaring constants in SQL
| От | Richard Broersma |
|---|---|
| Тема | Re: Declaring constants in SQL |
| Дата | |
| Msg-id | 396486430807301353v69f08653t128ca7602da1bbd9@mail.gmail.com обсуждение исходный текст |
| Ответ на | Declaring constants in SQL ("EXT-Rothermel, Peter M" <Peter.M.Rothermel@boeing.com>) |
| Список | 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 по дате отправления: