Re: plpgsql related question: intervals and variables

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Wilhelm Graiss <Wilhelm(dot)Graiss(at)bal(dot)bmlfuw(dot)gv(dot)at>, "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: plpgsql related question: intervals and variables
Date: 2003-10-21 18:43:02
Message-ID: 200310211143.02533.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Berkus
Aglio Database Solutions
San Francisco

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2003-10-21 18:54:30 Re: plpgsql related question: intervals and variables
Previous Message Adam Witney 2003-10-21 18:42:36 Re: how to create a multi columns return function ?