Как реализовать хранимую процедуру / функцию в postgresql версии 12? - PullRequest
0 голосов
/ 25 февраля 2020

Как я могу это реализовать? Я также запутался в синтаксисе?

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? *

1 Ответ

1 голос
/ 25 февраля 2020

Вот попытка перевести вашу функцию в правильный код:

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;
...