我正在寫一個函數,它將選擇並將得到的輸出合併到一個新表中 - 因此我試圖使用INTO函數。然而,我的獨立代碼工作,但一旦進入函數的地方,我得到一個錯誤,指出新的SELECT INTO表不是一個定義的變量(也許我失去了一些東西)。請看下面的代碼:PostgreSQL選擇INTO函數
CREATE OR REPLACE FUNCTION rev_1.calculate_costing_layer()
RETURNS trigger AS
$BODY$
BEGIN
-- This will create an intersection between pipelines and sum the cost to a new table for output
-- May need to create individual cost columns- Will also keep infrastructure costing seperated
--DROP table rev_1.costing_layer;
SELECT inyaninga_phases.geom, catchment_e_gravity_lines.name, SUM(catchment_e_gravity_lines.cost) AS gravity_sum
INTO rev_1.costing_layer
FROM rev_1.inyaninga_phases
ON ST_Intersects(catchment_e_gravity_lines.geom,inyaninga_phases.geom)
GROUP BY catchment_e_gravity_lines.name, inyaninga_phases.geom;
RETURN NEW;
END;
$BODY$
language plpgsql