pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Glaesemann <grzm@myrealbox.com>
To: Davidson, Robert <robdavid@amazon.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Using a parameter in Interval
Date: Wed, 22 Mar 2006 09:56:46 +0900
Message-ID: <06F2BDC4-2FCF-44BA-9DEC-CAAC518CE678@myrealbox.com> (raw)
In-Reply-To: <8333C841129E074E9F83FC80676BA76E0BEBEF@exchg-sea3-03.ant.amazon.com>
References: <8333C841129E074E9F83FC80676BA76E0BEBEF@exchg-sea3-03.ant.amazon.com>


On Mar 22, 2006, at 9:52 , Davidson, Robert wrote:

> ERROR:  syntax error at or near "CAST" at character 34
>
> QUERY:  SELECT  current_date - INTERVAL (CAST( $1  AS varchar) || '  
> weeks')
>
> CONTEXT:  SQL statement in PL/PgSQL function "testing" near line 2
The generally recommended way is something like:

test=# select '4'::integer * interval '1 week';
?column?
----------
28 days
(1 row)

or the more SQL compliant:

test=# select cast('4' as integer) * interval '1 week';
?column?
----------
28 days
(1 row)

Does that work for you?

Michael Glaesemann
grzm myrealbox com






view thread (5+ messages)  latest in thread

Message-ID: <06F2BDC4-2FCF-44BA-9DEC-CAAC518CE678@myrealbox.com>
Permalink:  ../06F2BDC4-2FCF-44BA-9DEC-CAAC518CE678@myrealbox.com/
Also on:    postgresql.org/message-id/06F2BDC4-2FCF-44BA-9DEC-CAAC518CE678@myrealbox.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: grzm@myrealbox.com, robdavid@amazon.com
  Subject: Re: Using a parameter in Interval
  In-Reply-To: <06F2BDC4-2FCF-44BA-9DEC-CAAC518CE678@myrealbox.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