pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: amutu@amutu.com
To: pgsql-bugs@postgresql.org
Subject: BUG #13805: plpgsql execute using expression evaluate wrong
Date: Tue, 08 Dec 2015 03:54:44 +0000
Message-ID: <20151208035444.5253.30717@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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)



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (6+ messages)  latest in thread

Message-ID: <20151208035444.5253.30717@wrigleys.postgresql.org>
Permalink:  ../20151208035444.5253.30717@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20151208035444.5253.30717@wrigleys.postgresql.org

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: amutu@amutu.com
  Subject: Re: BUG #13805: plpgsql execute using expression evaluate wrong
  In-Reply-To: <20151208035444.5253.30717@wrigleys.postgresql.org>
  References: <20151208035444.5253.30717@wrigleys.postgresql.org>

* 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