0
我的第一個功能會消耗UUID的數組,並返回從表一組的列:爲什麼Postgres不返回結果?
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;
請提供樣本數據,並顯示您的期望和你得到什麼。 –
fun1程序正常工作併產生正確的結果。 fun2產生沒有任何字段的空白結果。 –