Re: How to declare a variable in a postgresql query in sql language ?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: How to declare a variable in a postgresql query in sql language ?
Дата
Msg-id 8437.1325440918@sss.pgh.pa.us
обсуждение исходный текст
Ответ на How to declare a variable in a postgresql query in sql language ?  (Sara Harris <sarah@ips.gov.il>)
Список pgsql-novice
Sara Harris <sarah@ips.gov.il> writes:
> In MS SQL Server I can do this:
> DECLARE @myvar INT
> SET @myvar = 5

> SELECT *
> FROM somewhere
> WHERE something = @myvar

> How do I do the same in PostgreSQL in sql language?

You don't.  You need to use plpgsql if you need declared variables.

In practice, if you're coding in a style that would require local
variables, you're almost certainly going to need plpgsql anyway,
since plain SQL hasn't got any control structures either.

            regards, tom lane

В списке pgsql-novice по дате отправления: