如何在postgresql版本12中实现存储过程/函数?

如何在postgresql版本12中实现存储过程/函数?,postgresql,stored-functions,Postgresql,Stored Functions,我如何实施它?我对语法也感到困惑 创建或替换函数dailyyyy\u volation\u例程\u ispeed\u count integer、\u rlvd\u count integer、\u stopline\u count integer、\u error dir\u count integer ,\u错误车道\u计数整数,\u泽布拉克罗斯\u计数整数,\u总数\u计数整数 返回void作为$$ 开始 插入临时每日统计显示计数、rlvd计数、停车线计数、错误方向计数、错误车道计数、斑马

我如何实施它?我对语法也感到困惑


创建或替换函数dailyyyy\u volation\u例程\u ispeed\u count integer、\u rlvd\u count integer、\u stopline\u count integer、\u error dir\u count integer ,\u错误车道\u计数整数,\u泽布拉克罗斯\u计数整数,\u总数\u计数整数 返回void作为$$ 开始 插入临时每日统计显示计数、rlvd计数、停车线计数、错误方向计数、错误车道计数、斑马线计数、总计数 使用t1作为从临时每小时统计中选择SUMispeed\u count作为ispeed\u count, t3作为从温度每小时统计中选择SUMrlvd作为rlvd计数, t4作为从临时每小时统计中选择SUMstop_line_count作为stopline_count, t5作为从临时每小时统计中选择SumError_dir_count作为Error_dir_count, t6作为从临时每小时统计中选择SumError_lane_count作为Error_lane_count, t7作为选择SUMzebra_cross_count作为temp_hourly_统计中的zebra_cross_count, t8 as SELECT@tc:=SUMtotal\u count作为临时每小时统计的总天数, 选择不同的t1.速度计数,t3.速度计数,t4.停车线计数,t5.方向计数错误,t6.车道计数错误,t7.斑马交叉计数,t8.总天数计数 从t1、t3、t4、t5、t6、t7、t8限值1开始; 终止 $$ 语言SQL;
我想使用postgresql函数将数据从一个表放到另一个表?*

以下是将函数转换为正确代码的尝试:

CREATE OR REPLACE Function dailyyyy_volation_routine(
   _ispeed_count integer,
   _rlvd_count integer,
   _stopline_count integer,
   _wrongdir_count integer,
   _wronglane_count integer,
   _zebracross_count integer,
_total_count integer) RETURNS void AS
$$INSERT INTO temp_daily_stats(
   ispeed_count,
   rlvd_count,
   stopline_count,
   wrongdir_count,
   wronglane_count,
   zebracross_count,
   total_count
)
SELECT SUM(ispeed_count),
       SUM(rlvd_count),
       SUM(stop_line_count),
       SUM(wrong_dir_count),
       SUM(wrong_lane_count),
       SUM(zebra_cross_count),
       SUM(total_count)
FROM temp_hourly_stats$$ 
LANGUAGE SQL;

创建或替换函数dailyyyy\u volation\u routineispeed\u count integer返回void AS$$BEGIN INSERT INTO temp\u daily\u stats ispeed\u count从temp\u hourly\u stats中选择SUMispeed\u count AS ispeed\u count;END$$LANGUAGE SQL;我也这么做了,但是它说Insert附近或insertI的语法错误我使用的是postgreAh-hah的最新版本,但是你在回答中从来没有说过函数有一个同名的参数,这是不好的做法。在这种情况下,您必须限定该列。我将更新答案。我怀疑这在任何地方都是有效的。无论如何,我已尝试在我的答案中将您的代码转换为有效的SQL。SQL函数不使用BEGIN和END。删除这两行。先生,现在它显示这个错误错误:语法错误在或附近:=11:t8作为SELECT@tc:=SUMtotal\u count作为total\u day\u count from…我的语法错了吗?SELECT@tc:=SUMtotal\u count是无效的标准SQL,在Postgres中无效-这应该做什么?