From: bryan@unhwildhats.com
To: pgsql-bugs@postgresql.org
Subject: BUG #11526: WITH tables not accessible from function
Date: Tue, 30 Sep 2014 16:05:52 +0000
Message-ID: <20140930160552.17172.90970@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: 11526
Logged by: Bryan
Email address: bryan@unhwildhats.com
PostgreSQL version: 9.3.5
Operating system: Ubuntu 14.04
Description:
I need to access a temporary table created by a WITH statement in a function
called from the subsequent SELECT. I could not find any documentation
forbidding this behavior.
This is a self-contained example that should demonstrate the bug:
CREATE SCHEMA IF NOT EXISTS test;
SET SEARCH_PATH=test;
CREATE OR REPLACE FUNCTION test.func(table_name TEXT)
RETURNS TABLE(id INTEGER) AS $$
BEGIN
EXECUTE 'CREATE TEMPORARY TABLE results AS (SELECT * FROM
'||table_name||')';
RETURN QUERY(SELECT * FROM results);
END;
$$
LANGUAGE 'plpgsql';
WITH data AS
(
SELECT * FROM generate_series(1,4)
)
SELECT * FROM test.func('data'); -- This errors out
DROP TABLE IF EXISTS dummy;
CREATE TABLE dummy(id INTEGER);
INSERT INTO dummy VALUES(1),(2),(3),(4),(5);
SELECT * FROM test.func('dummy'); -- This succeeds
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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: bryan@unhwildhats.com
Subject: Re: BUG #11526: WITH tables not accessible from function
In-Reply-To: <20140930160552.17172.90970@wrigleys.postgresql.org>
References: <20140930160552.17172.90970@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