pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Пушкин Сергей <pushkinsv@gmail.com>
To: pgsql-bugs@postgresql.org
Subject: execution plan and record variable in dynamic sql
Date: Tue, 16 Dec 2014 13:19:52 +0700
Message-ID: <op.xqx6jed6gskoan@pushkinsv.ood.local> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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


-- 
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 (5+ messages)  latest in thread

Message-ID: <op.xqx6jed6gskoan@pushkinsv.ood.local>
Permalink:  ../op.xqx6jed6gskoan@pushkinsv.ood.local/
Also on:    postgresql.org/message-id/op.xqx6jed6gskoan@pushkinsv.ood.local

 · 

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: pushkinsv@gmail.com
  Subject: Re: execution plan and record variable in dynamic sql
  In-Reply-To: <op.xqx6jed6gskoan@pushkinsv.ood.local>
  References: <op.xqx6jed6gskoan@pushkinsv.ood.local>

* 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