Re: Incorrect (?) escape of the $1

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: andrew(at)pillette(dot)com
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Incorrect (?) escape of the $1
Date: 2003-12-22 22:16:24
Message-ID: 18598.1072131384@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

andrew(at)pillette(dot)com writes:
> Is there any magic sequence of quotes or backslashes that will get the following (simplified version) to do the obvious thing?
> CREATE FUNCTION doesnt_work(integer) RETURNS date LANGUAGE SQL AS
> 'SELECT (date ''epoch'' + interval '' $1 day'')::date ' STRICT IMMUTABLE;

> No variable interpolation is performed; the interval 1 day is always used.

You could probably make it work via string concatenation (||)
if you were absolutely intent on it, but far easier is to use the
number-times-interval operator:

CREATE FUNCTION does_work(integer) RETURNS date LANGUAGE SQL AS
'SELECT (date ''epoch'' + $1 * interval ''1 day'')::date'
STRICT IMMUTABLE;

regards, tom lane

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2003-12-22 22:27:22 Re: INDEX and NULL
Previous Message Tom Lane 2003-12-22 22:08:12 Re: pl/pgSQL sequence question