Re: plpgsql related question: intervals and variables

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: 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 21:39:26
Message-ID: 20031021143506.M52534@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, 21 Oct 2003, Josh Berkus wrote:

> > 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'');

I think that something like
ez := heute + vk * interval '1 day';
might be better in general.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Abdul Wahab Dahalan 2003-10-22 08:02:11 Timestamp
Previous Message Tom Lane 2003-10-21 19:08:39 Re: function problem