1
我試圖將PERFORM與WITH查詢一起使用,該查詢返回多行。在多行的情況下使用WITH子句進行執行
CREATE OR REPLACE FUNCTION test_function() RETURNS void AS $$
BEGIN
PERFORM (
WITH selection AS (
SELECT id,
ROW_NUMBER() OVER w AS r,
first_value(id) OVER w AS first_value,
nth_value(id, 5) OVER w AS last_value
FROM mytable
WINDOW w AS (PARTITION BY v.ability_id ORDER BY unit_id ASC)
)
create_question(id, 1, 1, 1)
FROM selection
WHERE ability_id IN (
SELECT ability_id
FROM selection
WHERE last_value > 0.5
ORDER BY first_value DESC
)
AND selection.r <= 5
);
END;
$$ LANGUAGE plpgsql;
,我得到的錯誤:
ERROR: more than one row returned by a subquery used as an expression
Postgres的醫生說不能這樣做:
For WITH queries, use PERFORM and then place the query in parentheses. (In this case, the query can only return one row.)
可以做些什麼,以書面形式,從解決這個問題,除了With查詢(在這裏稱爲選擇)兩次?
我在您的CTE中看不到'ability_id'。 – wildplasser
是的,我簡化了查詢以提供我想要實現的功能。實際的人有它。 –