Re: subtracting from a date

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: subtracting from a date
Дата
Msg-id 1391724463623-5790923.post@n5.nabble.com
обсуждение исходный текст
Ответ на Re: subtracting from a date  (Jay Vee <jvsrvcs@gmail.com>)
Список pgsql-general
jvsrvcs wrote
> I tried that but get an error
>     v_start_date date;
>     v_minus_one_year date;
>
> I have v_start_date to start with and want to subtract one year and put
> into v_minus_one_year
>
>   select v_start_date - interval '1 yr' as v_minus_one_year;
>
>
>
> ---  I get:
>
> ERROR:  query has no destination for result data

The relevant section of the documentation you need to study is:

http://www.postgresql.org/docs/9.3/interactive/plpgsql-statements.html

There are two basic ways to assign to variables:

variable := expression
SELECT expression[s] INTO variable[s] FROM ... || SELECT expression[s] FROM
... INTO variable[s]

Your problem is that:

SELECT expression AS "variable" FROM ... simply provides an alias for the
expression and has nothing to do with any variables in the surrounding
program.  The "INTO" keyword is needed to avoid ambiguity.

pl/pgsql has the unique behavior that using SELECT without INTO results in
an error.  If you really need to execute a SELECT and ignore the content
selected you have to use PERFORM.  The error you saw was this behavior in
action.

David J.





--
View this message in context: http://postgresql.1045698.n5.nabble.com/subtracting-from-a-date-tp5790891p5790923.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


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

Предыдущее
От: wd
Дата:
Сообщение: Exclude pg_log directory when running pg_basebackup?
Следующее
От: Andy Colson
Дата:
Сообщение: Re: Offending My Tender Sensibilities -OR- OLTP on a Star Schema