Re: plpgsql related question: intervals and variables - Mailing list pgsql-sql

From Josh Berkus
Subject Re: plpgsql related question: intervals and variables
Date
Msg-id 200310211143.02533.josh@agliodbs.com
Whole thread Raw
In response to plpgsql related question: intervals and variables  (Wilhelm Graiss <Wilhelm.Graiss@bal.bmlfuw.gv.at>)
Responses Re: plpgsql related question: intervals and variables  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
List 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 by date:

Previous
From: Adam Witney
Date:
Subject: Re: how to create a multi columns return function ?
Next
From: Richard Huxton
Date:
Subject: Re: plpgsql related question: intervals and variables