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

From amutu@amutu.com
Subject BUG #13805: plpgsql execute using expression evaluate wrong
Date
Msg-id 20151208035444.5253.30717@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #13805: plpgsql execute using expression evaluate wrong  (David Gould <daveg@sonic.net>)
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      13805
Logged by:          Jov
Email address:      amutu@amutu.com
PostgreSQL version: 9.4.5
Operating system:   CentOS 6
Description:

test case:

CREATE OR REPLACE FUNCTION public.test()
RETURNS void
LANGUAGE plpgsql
AS $function$
declare
n int = 4;
rt timestamp[];
rt2 interval;
begin
execute $$select array_agg(g.i) from generate_series(now() - ('$1
month')::interval,now(),'1 month') g(i)$$ into r
t using n;
raise notice 'rt : %',rt;

execute $$select array_agg(g.i) from generate_series(now() - ($1::varchar ||
' month')::interval,now(),'1 month')
g(i)$$ into rt using n;
raise notice 'rt : %',rt;

execute $$select ('$1 month')::interval $$ into rt2 using n;
raise notice 'rt2 : %',rt2;

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

$function$
~
~
No changes
db_001=# select * from test();
NOTICE: rt : {"2015-11-08 11:46:28.500811","2015-12-08
11:46:28.500811"}-----wrong answer,should 4 elements
NOTICE: rt : {"2015-08-08 11:46:28.500811","2015-09-08
11:46:28.500811","2015-10-08 11:46:28.500811","2015-11-08
11:46:28.500811","2015-12-08 11:46:28.500811"}
NOTICE: rt2 : 1 mon-----wrong,should 4 mons
NOTICE: rt2 : 4 mons
test
------

(1 row)

pgsql-bugs by date:

Previous
From: Jeff Janes
Date:
Subject: Re: BUG #13804: pg_restore returns unexpected error
Next
From: David Gould
Date:
Subject: Re: BUG #13805: plpgsql execute using expression evaluate wrong