如何使用 table 行值作为函数参数
How to use table row values as function parameters
Table ko
用于给crtKAIVE
函数传递参数。
table 总是单行。
我尝试了下面的代码但出现了错误
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)
您正在使用 Postgres 9.3 中引入的 lateral join
。早期版本的语法不正确。
在 Postgres 9.1 中你可以试试
select doktyyp, crtkaive(doktyyp) from ko;
或
select * from crtkaive((select doktyyp from ko));
Table ko
用于给crtKAIVE
函数传递参数。
table 总是单行。
我尝试了下面的代码但出现了错误
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)
您正在使用 Postgres 9.3 中引入的 lateral join
。早期版本的语法不正确。
在 Postgres 9.1 中你可以试试
select doktyyp, crtkaive(doktyyp) from ko;
或
select * from crtkaive((select doktyyp from ko));