From: | andrew(at)pillette(dot)com |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Subject: | Re: Incorrect (?) escape of the $1 |
Date: | 2003-12-23 00:22:35 |
Message-ID: | 200312230022.hBN0MZk30298@pillette.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
|| does NOT work but your solution is so much nicer anyway.
Thanks. Very clever.
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote ..
> 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
From | Date | Subject | |
---|---|---|---|
Next Message | Marek Lewczuk | 2003-12-23 08:28:01 | Re: Installing PostgreSQL on Windowns 2000 |
Previous Message | Tom Lane | 2003-12-22 22:27:22 | Re: INDEX and NULL |