【发布时间】:2018-01-05 17:13:36
【问题描述】:
我正在编写一个函数,它将选择并将结果输出求和到一个新表中 - 因此我尝试使用 INTO 函数。但是,我的独立代码可以工作,但是一旦放入函数中,我就会收到一条错误消息,指出新的 SELECT 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
【问题讨论】:
标签: postgresql postgis create-table insert-into