如何在 postgresql 版本 12 中实现存储 procedure/function?
How to implement stored procedure/function in postgresql version 12?
我该如何实施?我也对语法感到困惑?
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 $$
BEGIN
INSERT INTO temp_daily_stats(ispeed_count,rlvd_count,stopline_count,wrongdir_count,wronglane_count,zebracross_count,total_count)
with t1 as (SELECT SUM(ispeed_count) as ispeed_count from temp_hourly_stats),
t3 as (SELECT SUM(rlvd_count) as rlvd_count from temp_hourly_stats),
t4 as (SELECT SUM(stop_line_count) as stopline_count from temp_hourly_stats),
t5 as (SELECT SUM(wrong_dir_count) as wrong_dir_count from temp_hourly_stats),
t6 as (SELECT SUM(wrong_lane_count) as wrong_lane_count from temp_hourly_stats),
t7 as (SELECT SUM(zebra_cross_count) as zebra_cross_count from temp_hourly_stats),
t8 as (SELECT @tc := SUM(total_count) as total_day_count from temp_hourly_stats),
SELECT DISTINCT t1.ispeed_count,t3.rlvd_count,t4.stopline_count,t5.wrong_dir_count,t6.wrong_lane_count,t7.zebra_cross_count,t8.total_day_count
FROM t1,t3,t4,t5,t6,t7,t8 limit 1;
END
$$
LANGUAGE SQL;
我想使用 postgresql 函数将数据从一个 table 放到另一个?*
尝试将您的函数转换为正确的代码:
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;
我该如何实施?我也对语法感到困惑?
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 $$
BEGIN
INSERT INTO temp_daily_stats(ispeed_count,rlvd_count,stopline_count,wrongdir_count,wronglane_count,zebracross_count,total_count)
with t1 as (SELECT SUM(ispeed_count) as ispeed_count from temp_hourly_stats),
t3 as (SELECT SUM(rlvd_count) as rlvd_count from temp_hourly_stats),
t4 as (SELECT SUM(stop_line_count) as stopline_count from temp_hourly_stats),
t5 as (SELECT SUM(wrong_dir_count) as wrong_dir_count from temp_hourly_stats),
t6 as (SELECT SUM(wrong_lane_count) as wrong_lane_count from temp_hourly_stats),
t7 as (SELECT SUM(zebra_cross_count) as zebra_cross_count from temp_hourly_stats),
t8 as (SELECT @tc := SUM(total_count) as total_day_count from temp_hourly_stats),
SELECT DISTINCT t1.ispeed_count,t3.rlvd_count,t4.stopline_count,t5.wrong_dir_count,t6.wrong_lane_count,t7.zebra_cross_count,t8.total_day_count
FROM t1,t3,t4,t5,t6,t7,t8 limit 1;
END
$$
LANGUAGE SQL;
我想使用 postgresql 函数将数据从一个 table 放到另一个?*
尝试将您的函数转换为正确的代码:
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;