如何使用表行值作为函数参数

时间:2016-05-14 20:41:00

标签: sql postgresql postgresql-9.1

ko用于将参数传递给crtKAIVE函数。 这个表总是单行。

我尝试了以下代码,但收到了错误

ERROR:  function expression in FROM cannot refer to other relations of same query level
LINE 15: select * from ko, crtkaive(ko.doktyyp)

如何解决这个问题,以便ko可以用来将参数传递给crtkaive? 使用Postgres 9.1及更高版本。

CREATE or replace FUNCTION public.crtKAIVE(
_doktyybid text default 'GVY'
)
RETURNS TABLE (
id integer
)
AS $f_crkaive$
select 1
$f_crkaive$ LANGUAGE sql STABLE;

create temp  table ko ( doktyyp text ) on commit drop;

insert into ko values ('G');

select * from ko, crtkaive(ko.doktyyp)

1 个答案:

答案 0 :(得分:0)

您正在使用Postgres 9.3中引入的lateral join。在早期版本中语法不正确。

在Postgres 9.1中,您可以尝试

select doktyyp, crtkaive(doktyyp) from ko;

select * from crtkaive((select doktyyp from ko));