作为一个例子:
=> create or replace function testf(x integer)
returns table(a integer, b integer)
language sql
as $function$
select * from (values(1,2)) as foo(a,b)
$function$;
=> select testf(3);
testf
-------
(1,2)
=> select * from testf(3);
a | b
---+---
1 | 2
=> select s.n, testf(s.n) from (select 3 as n union select 4) s;
n | testf
---+-------
3 | (1,2)
4 | (1,2) <-- not a table (or row with column names)
=> select * from testf(s.n) from (select 3 as n) s;
ERROR: syntax error at or near "from" LINE 1: select * from testf(s.n) from (select 3 as n) s;
答案 0 :(得分:2)
使用LATERAL
子查询:
SELECT *
FROM (VALUES (3), (4)) AS s(n)
, testf(s.n);
逗号是CROSS JOIN LATERAL
的简短表示法,因为LATERAL
自动使用FROM
子句中的set-returns函数。
相关: