351
351
select t.a, t, t.a from foo1(10000) t limit 1;
353
353
drop function foo1(n integer);
355
-- test use of SQL functions returning record
356
-- this is supported in some cases where the query doesn't specify
357
-- the actual record type ...
359
create function array_to_set(anyarray) returns setof record as $$
360
select i AS "index", $1[i] AS "value" from generate_subscripts($1, 1) i
361
$$ language sql strict immutable;
363
select array_to_set(array['one', 'two']);
364
select * from array_to_set(array['one', 'two']) as t(f1 int,f2 text);
365
select * from array_to_set(array['one', 'two']); -- fail
367
create temp table foo(f1 int8, f2 int8);
369
create function testfoo() returns record as $$
370
insert into foo values (1,2) returning *;
374
select * from testfoo() as t(f1 int8,f2 int8);
375
select * from testfoo(); -- fail
377
drop function testfoo();
379
create function testfoo() returns setof record as $$
380
insert into foo values (1,2), (3,4) returning *;
384
select * from testfoo() as t(f1 int8,f2 int8);
385
select * from testfoo(); -- fail
387
drop function testfoo();