pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #11526: WITH tables not accessible from function
2+ messages / 2 participants
[nested] [flat]

* BUG #11526: WITH tables not accessible from function
@ 2014-09-30 16:05 bryan@unhwildhats.com
  2014-09-30 20:46 ` Re: BUG #11526: WITH tables not accessible from function Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: bryan@unhwildhats.com @ 2014-09-30 16:05 UTC (permalink / raw)
  To: pgsql-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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #11526: WITH tables not accessible from function
  2014-09-30 16:05 BUG #11526: WITH tables not accessible from function bryan@unhwildhats.com
@ 2014-09-30 20:46 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2014-09-30 20:46 UTC (permalink / raw)
  To: bryan@unhwildhats.com; +Cc: pgsql-bugs

bryan@unhwildhats.com writes:
> 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.

You're imagining that a WITH clause creates an actual table.  It does not,
any more than, say, a function call in the FROM clause does.  It's just
a name accessible within the query the WITH is attached to.  Sorry.

			regards, tom lane


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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2014-09-30 20:46 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-09-30 16:05 BUG #11526: WITH tables not accessible from function bryan@unhwildhats.com
2014-09-30 20:46 ` Tom Lane <tgl@sss.pgh.pa.us>

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