execution plan and record variable in dynamic sql

From: Пушкин Сергей <pushkinsv(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: execution plan and record variable in dynamic sql
Date: 2014-12-16 06:19:52
Message-ID: op.xqx6jed6gskoan@pushkinsv.ood.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


Hello!

The following code results in error, if executed in one session:

create or replace function exec(sql text)
returns void language plpgsql as $_$
declare
r record;
begin
execute sql into r;

-- works ok everytime
raise notice 'r %', r;

-- fails if type of r.status differs from first exec invocation
-- making r.status inaccessible
raise notice 'r.status %', r.status;
end;
$_$;

select * from exec($$ select 1 as status $$);
select * from exec($$ select 'test' as status $$);

Results:

NOTICE: r (1)
NOTICE: r.status 1
exec
------

(1 row)

NOTICE: r (test)
ERROR: type of parameter 4 (unknown) does not match that when preparing
the plan (integer)
Context: PL/pgSQL function exec(text) line 8 at RAISE

Version:
PostgreSQL 9.4rc1 on x86_64-unknown-linux-gnu, compiled by gcc (Debian
4.9.2-2) 4.9.2, 64-bit
also checked on PostgreSQL 9.1.9

Thanks!
--
Serge Pushkin

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G Johnston 2014-12-16 06:59:34 Re: execution plan and record variable in dynamic sql
Previous Message David G Johnston 2014-12-16 02:35:03 Re: BUG #12241: uninitialized value $lib_path