有一個返回3個參數,其中一個是複合類型的函數:
CREATE OR REPLACE FUNCTION f1(
p_text text,
OUT result_status_id smallint,
OUT result_status_msg text,
OUT result_my_type my_type
)
RETURNS record AS
$BODY$
--body here
$BODY$
LANGUAGE 'plpgsql' VOLATILE SECURITY DEFINER
COST 100
的複合型my_type看起來像以下:
CREATE TYPE my_type AS
(d_real real,
d_int1 integer,
d_int2 integer,
d_int3 integer,
d_int4 integer,
d_int5 integer,
d_int6 integer,
d_int7 integer,
d_int8 integer,
d_int9 integer,
d_int10 integer,
d_bool boolean,
d_date date,
d_text text
);
還有另外一個函數F2,在它的身上調用函數F1:
CREATE OR REPLACE FUNCTION f2(
p_text text
)
RETURNS record AS
$BODY$
DECLARE
l_status_id smallint;
l_status_msg text;
l_my_type my_type;
BEGIN
--some logic here
--this statement fails
SELECT * FROM f1(p_text) 'x'
INTO l_status_id, l_status_msg, l_my_type;
--logic continues here
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE SECURITY DEFINER
COST 100;
的問題是,當高管使用函數sql我收到以下錯誤:
ERROR: "l_my_type" is not a scalar variable
如何可能從另一個函數獲取複合類型的對象?
這也沒關係,它在x附近沒有單引號。沒有別名功能也是 – Tim
重要的部分是你遇到的錯誤的解釋(對你*和*普通大衆)。如前所述,它有多種方式。在你已經發布簡單任務後,我選擇了一個不同的例子。 –