mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-28 17:26:59 +08:00
Fix things so that you can still do "select foo()" where foo is a SQL
function returning setof record. This used to work, more or less accidentally, but I had broken it while extending the code to allow materialize-mode functions to be called in select lists. Add a regression test case so it doesn't get broken again. Per gripe from Greg Davidson.
This commit is contained in:
@ -763,3 +763,70 @@ select t.a, t, t.a from foo1(10000) t limit 1;
|
||||
(1 row)
|
||||
|
||||
drop function foo1(n integer);
|
||||
-- test use of SQL functions returning record
|
||||
-- this is supported in some cases where the query doesn't specify
|
||||
-- the actual record type ...
|
||||
create function array_to_set(anyarray) returns setof record as $$
|
||||
select i AS "index", $1[i] AS "value" from generate_subscripts($1, 1) i
|
||||
$$ language sql strict immutable;
|
||||
select array_to_set(array['one', 'two']);
|
||||
array_to_set
|
||||
--------------
|
||||
(1,one)
|
||||
(2,two)
|
||||
(2 rows)
|
||||
|
||||
select * from array_to_set(array['one', 'two']) as t(f1 int,f2 text);
|
||||
f1 | f2
|
||||
----+-----
|
||||
1 | one
|
||||
2 | two
|
||||
(2 rows)
|
||||
|
||||
select * from array_to_set(array['one', 'two']); -- fail
|
||||
ERROR: a column definition list is required for functions returning "record"
|
||||
LINE 1: select * from array_to_set(array['one', 'two']);
|
||||
^
|
||||
create temp table foo(f1 int8, f2 int8);
|
||||
create function testfoo() returns record as $$
|
||||
insert into foo values (1,2) returning *;
|
||||
$$ language sql;
|
||||
select testfoo();
|
||||
testfoo
|
||||
---------
|
||||
(1,2)
|
||||
(1 row)
|
||||
|
||||
select * from testfoo() as t(f1 int8,f2 int8);
|
||||
f1 | f2
|
||||
----+----
|
||||
1 | 2
|
||||
(1 row)
|
||||
|
||||
select * from testfoo(); -- fail
|
||||
ERROR: a column definition list is required for functions returning "record"
|
||||
LINE 1: select * from testfoo();
|
||||
^
|
||||
drop function testfoo();
|
||||
create function testfoo() returns setof record as $$
|
||||
insert into foo values (1,2), (3,4) returning *;
|
||||
$$ language sql;
|
||||
select testfoo();
|
||||
testfoo
|
||||
---------
|
||||
(1,2)
|
||||
(3,4)
|
||||
(2 rows)
|
||||
|
||||
select * from testfoo() as t(f1 int8,f2 int8);
|
||||
f1 | f2
|
||||
----+----
|
||||
1 | 2
|
||||
3 | 4
|
||||
(2 rows)
|
||||
|
||||
select * from testfoo(); -- fail
|
||||
ERROR: a column definition list is required for functions returning "record"
|
||||
LINE 1: select * from testfoo();
|
||||
^
|
||||
drop function testfoo();
|
||||
|
||||
@ -351,3 +351,37 @@ reset work_mem;
|
||||
select t.a, t, t.a from foo1(10000) t limit 1;
|
||||
|
||||
drop function foo1(n integer);
|
||||
|
||||
-- test use of SQL functions returning record
|
||||
-- this is supported in some cases where the query doesn't specify
|
||||
-- the actual record type ...
|
||||
|
||||
create function array_to_set(anyarray) returns setof record as $$
|
||||
select i AS "index", $1[i] AS "value" from generate_subscripts($1, 1) i
|
||||
$$ language sql strict immutable;
|
||||
|
||||
select array_to_set(array['one', 'two']);
|
||||
select * from array_to_set(array['one', 'two']) as t(f1 int,f2 text);
|
||||
select * from array_to_set(array['one', 'two']); -- fail
|
||||
|
||||
create temp table foo(f1 int8, f2 int8);
|
||||
|
||||
create function testfoo() returns record as $$
|
||||
insert into foo values (1,2) returning *;
|
||||
$$ language sql;
|
||||
|
||||
select testfoo();
|
||||
select * from testfoo() as t(f1 int8,f2 int8);
|
||||
select * from testfoo(); -- fail
|
||||
|
||||
drop function testfoo();
|
||||
|
||||
create function testfoo() returns setof record as $$
|
||||
insert into foo values (1,2), (3,4) returning *;
|
||||
$$ language sql;
|
||||
|
||||
select testfoo();
|
||||
select * from testfoo() as t(f1 int8,f2 int8);
|
||||
select * from testfoo(); -- fail
|
||||
|
||||
drop function testfoo();
|
||||
|
||||
Reference in New Issue
Block a user