pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: Wilhelm Graiss <Wilhelm.Graiss@bal.bmlfuw.gv.at>
To: 'pgsql-sql@postgresql.org' <pgsql-sql@postgresql.org>
Subject: Re: plpgsql related question: intervals and variables
Date: Tue, 21 Oct 2003 11:43:02 -0700
Message-ID: <200310211143.02533.josh@agliodbs.com> (raw)
In-Reply-To: <40925A3BA1EBD711A35C000102B6E57D06C9A7@BAL_PROXY00>
References: <40925A3BA1EBD711A35C000102B6E57D06C9A7@BAL_PROXY00>

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




view thread (4+ messages)  latest in thread

Message-ID: <200310211143.02533.josh@agliodbs.com>
Permalink:  ../200310211143.02533.josh@agliodbs.com/
Also on:    postgresql.org/message-id/200310211143.02533.josh@agliodbs.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: josh@agliodbs.com, Wilhelm.Graiss@bal.bmlfuw.gv.at
  Subject: Re: plpgsql related question: intervals and variables
  In-Reply-To: <200310211143.02533.josh@agliodbs.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox