我的第一个函数使用一个UUID数组并从表中返回一组行:
CREATE OR REPLACE FUNCTION fun1 (
"UUID_" uuid []
)
RETURNS SETOF service AS
$body$
with recursive tree as (
SELECT * FROM service
WHERE id = ANY($1)
UNION ALL
SELECT service.* FROM service
JOIN tree ON service.id = tree.parent_id)
select distinct * from tree;
$body$
LANGUAGE 'sql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100 ROWS 1000;
现在我想写另一个将UUID列表作为varchar使用,并返回与第一个函数相同的数据。
我的不好尝试:
CREATE OR REPLACE FUNCTION fun2 (
"UUID_" varchar
)
RETURNS TABLE (
"ID" uuid,
"NAME" varchar,
"PARENT_ID" uuid
) AS
$body$
BEGIN
RETURN QUERY
with recursive tree as (
SELECT * FROM service
WHERE id = ANY(string_to_array($1, ',')::UUID[])
UNION ALL
SELECT service.* FROM service
JOIN tree ON service.id = tree.parent_id)
select distinct(ID), name, parent_id from tree;
END;
$body$
LANGUAGE 'plpgsql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100 ROWS 1000;
答案 0 :(得分:0)
我会自己回答:
函数fun1可以在我使用它时使用varchar转换为UUID数组。 所以我可以写:
select * from fun1('{some UUID array as varchar}'::UUID[]);