2016-05-14 78 views
0

表格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) 

回答

0

您正在使用PostgreSQL 9.3中引入的lateral join。在早期版本中語法不正確。

在Postgres的9.1,你可以嘗試

select doktyyp, crtkaive(doktyyp) from ko; 

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