Re: plpgsql related question: intervals and variables

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: plpgsql related question: intervals and variables
Дата
Msg-id 200310211143.02533.josh@agliodbs.com
обсуждение исходный текст
Ответ на plpgsql related question: intervals and variables  (Wilhelm Graiss <Wilhelm.Graiss@bal.bmlfuw.gv.at>)
Ответы Re: plpgsql related question: intervals and variables  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Список pgsql-sql
Willhelm,

> Begin
>
>    heute := ''today'';
> Select Into vk ourcolumn From table where other = foo;
>    If vk > 0 Then
>     vk_txt := ''Vorkuehlung notwendig'';
>     ez  := heute + interval ''vk days'';

PL/pgSQL handles variable like SQL, not like PHP or Perl.  You can't do a
variable substitution inside quotes, and you need to cast:

ez  := heute + interval (cast(vk as text) ||  '' days'');

Also, the string 'today' has no special meaning in PL/pgSQL.  I think you want
now() instead.

I'm afraid that you're going to need a tutorial on SQL datatypes, casting, and
similar issues ... I wish I had one to recommend to you.  Just keep in mind
that SQL scripting languages (like PL/pgSQL) are not Perl!

--
-Josh BerkusAglio Database SolutionsSan Francisco



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

Предыдущее
От: Adam Witney
Дата:
Сообщение: Re: how to create a multi columns return function ?
Следующее
От: Richard Huxton
Дата:
Сообщение: Re: plpgsql related question: intervals and variables