Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YunEK-0001TX-L1 for pgsql-bugs@arkaria.postgresql.org; Tue, 19 May 2015 19:31:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YunEJ-0005Oz-JM for pgsql-bugs@arkaria.postgresql.org; Tue, 19 May 2015 19:31:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YulII-00062v-IM for pgsql-bugs@postgresql.org; Tue, 19 May 2015 17:27:06 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1YulIF-0004lO-Uq for pgsql-bugs@postgresql.org; Tue, 19 May 2015 17:27:05 +0000 MIME-Version: 1.0 Subject: BUG #13317: Cannot select multiple columns from multiple rows returned from PL/Python function To: pgsql-bugs@postgresql.org From: cpburnz@gmail.com Date: Tue, 19 May 2015 17:26:19 +0000 Message-ID: <20150519172619.26515.48844@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 13317 Logged by: Caleb P. Burns Email address: cpburnz@gmail.com PostgreSQL version: 9.3.6 Operating system: Ubuntu 12.04.5 Description: If I define a SQL function as: CREATE FUNCTION sql_test() RETURNS TABLE (a INTEGER, b INTEGER) AS $$ SELECT 1, 2 UNION ALL SELECT 3, 4 $$ LANGUAGE sql IMMUTABLE ROWS 2; I can select the values from both columns: postgres=# SELECT (sql_test()).*; a | b ---+--- 1 | 2 3 | 4 (2 rows) I can also do the same for a PL/pgSQL function: CREATE FUNCTION plpgsql_test() RETURNS TABLE (a INTEGER, b INTEGER) AS $$ BEGIN RETURN QUERY SELECT 1, 2 UNION ALL SELECT 3, 4; END $$ LANGUAGE plpgsql IMMUTABLE ROWS 2; postgres=# SELECT (plpgsql_test()).*; a | b ---+--- 1 | 2 3 | 4 (2 rows) If I try to do the same for a PL/Python (3u) function, the query will run for more than 5 or 10 minutes and never finish: CREATE FUNCTION plpython_yield_test() RETURNS TABLE (a INTEGER, b INTEGER) AS $$ yield (1, 2) yield (3, 4) $$ LANGUAGE plpython3u IMMUTABLE ROWS 2; postgres=# SELECT (plpython_yield_test()).*; ^CCancel request sent Cancel request sent ERROR: canceling statement due to user request CREATE FUNCTION plpython_return_test() RETURNS TABLE (a INTEGER, b INTEGER) AS $$ return [(1, 2), (3, 4)] $$ LANGUAGE plpython3u IMMUTABLE ROWS 2; postgres=# SELECT (plpython_return_test()).*; ^CCancel request sent Cancel request sent ERROR: canceling statement due to user request However, selecting only a single column works. postgres=# SELECT (plpython_yield_test()).a; a --- 1 3 (2 rows) postgres=# SELECT (plpython_yield_test()).b; b --- 2 4 (2 rows) postgres=# SELECT (plpython_return_test()).a; a --- 1 3 (2 rows) postgres=# SELECT (plpython_return_test()).b; b --- 2 4 (2 rows) Or if only one row is returned, then the query finishes: CREATE FUNCTION plpython_return_test2() RETURNS TABLE (a INTEGER, b INTEGER) AS $$ return [(5, 6)] $$ LANGUAGE plpython3u IMMUTABLE ROWS 1; SELECT (plpython_return_test2()).*; a | b ---+--- 5 | 6 (1 row) Running EXPLAIN does not reveal anything: postgres=# EXPLAIN SELECT (plpython_return_test()).a; QUERY PLAN ------------------------------------------ Result (cost=0.00..0.27 rows=2 width=0) (1 row) postgres=# EXPLAIN SELECT (plpython_return_test()).*; QUERY PLAN ------------------------------------------ Result (cost=0.00..0.52 rows=2 width=0) (1 row) However, EXPLAIN ANALYZE will not finish for the multiple columns and rows: postgres=# EXPLAIN ANALYZE SELECT (plpython_return_test()).a; QUERY PLAN ------------------------------------------------------------------------------------ Result (cost=0.00..0.27 rows=2 width=0) (actual time=0.056..0.063 rows=2 loops=1) Total runtime: 0.076 ms (2 rows) postgres=# EXPLAIN ANALYZE SELECT (plpython_return_test()).*; ^CCancel request sent Cancel request sent ERROR: canceling statement due to user request postgres=# EXPLAIN ANALYZE SELECT (plpython_return_test2()).*; QUERY PLAN ------------------------------------------------------------------------------------ Result (cost=0.00..0.51 rows=1 width=0) (actual time=0.089..0.106 rows=1 loops=1) Total runtime: 0.119 ms (2 rows) This appears to be a bug that selecting from multiple columns returned from a PL/Python function returning multiple rows does not work (never finishes). NOTE: This issue is also present on a Windows machine running PostgreSQL 9.1.0. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs