Re: BUG #13805: plpgsql execute using expression evaluate wrong - Mailing list pgsql-bugs

From David Gould
Subject Re: BUG #13805: plpgsql execute using expression evaluate wrong
Date
Msg-id 20151207220847.4da716e1@engels
Whole thread Raw
In response to BUG #13805: plpgsql execute using expression evaluate wrong  (amutu@amutu.com)
Responses Re: BUG #13805: plpgsql execute using expression evaluate wrong
Re: BUG #13805: plpgsql execute using expression evaluate wrong
List pgsql-bugs
On Tue, 08 Dec 2015 03:54:44 +0000
amutu@amutu.com wrote:


> execute $$select ('$1 month')::interval $$ into rt2 using n;
> raise notice 'rt2 : %',rt2;
>=20
> execute $$select ($1::varchar || ' month')::interval $$ into rt2 using n;
> raise notice 'rt2 : %',rt2;
> end;

> NOTICE: rt2 : 1 mon-----wrong=EF=BC=8Cshould 4 mons
> NOTICE: rt2 : 4 mons

You may have found a bug, but if so, it is not where you think it is. The
expression: '$1 month' is a text literal. PL/PGsql does not interpolate $n
like a shell, it only does the substitution where a variable could
ordinarily exist.

However, it does seem a little odd that the literal syntax for
intervals accepts the '$':

postgres=3D# select '$1 month'::interval, '$4 month'::interval;
 interval | interval=20
----------+----------
 1 mon    | 4 mons
(1 row)

I would have expected it to raise an error. The documentation does not shed
any light on this. Anyone?

-dg=20

--=20
David Gould              510 282 0869         daveg@sonic.net
If simplicity worked, the world would be overrun with insects.

pgsql-bugs by date:

Previous
From: amutu@amutu.com
Date:
Subject: BUG #13805: plpgsql execute using expression evaluate wrong
Next
From: Jov
Date:
Subject: Re: BUG #13805: plpgsql execute using expression evaluate wrong