我创建了函数并想分配查询的可变结果:
CREATE OR REPLACE FUNCTION GetData
(
OUT outValue integer
)
AS $$
DECLARE
records "Records";
BEGIN
records := (SELECT "Value1" FROM "Records");
outValue := (SELECT sum("Value1") FROM records)
END;
$$ LANGUAGE plpgsql;
但是,postgresql 说:
"ERROR: subquery in an expression returned more than one row."
如果声明类型为 的变量<"Records"%ROWTYPE>
,我们会得到相同的结果错误。
如何用查询结果声明变量?