1

我有以下不同的工作查询分别运行,我想使用 PostGreSQL 中的一些存储过程或任何可用方法一次性运行所有这些查询。

 SELECT obu_id, trip_id, start_time, end_time, end_time - LEAD(start_time)     OVER(PARTITION       BY obu_id ORDER BY start_time) AS diff FROM clean_trips_byobu;

下一个查询

 UPDATE clean_trips_byobu c

 SET    dwell_time = COALESCE(u.diff, interval '-1 hour')

 FROM (SELECT obu_id, trip_id, start_time, end_time,end_time - lead(start_time) OVER   (PARTITION BY obu_id                ORDER BY start_time) AS diff FROM  clean_trips_byobu) u

WHERE (c.obu_id, c.trip_id, c.start_time, c.end_time)
 =(u.obu_id, u.trip_id, u.start_time, u.end_time)

 AND c.dwell_time IS DISTINCT FROM COALESCE(u.diff, interval '-1 hour');

下一个查询

 UPDATE public.clean_trips_byobu
 SET trip_dist = clean_trips.bktp_mt_total
 FROM public.clean_trips
 WHERE public.clean_trips.obu_id = clean_trips_byobu.obu_id
 AND clean_trips.bktp_trip_id = clean_trips_byobu.trip_id;

我想将所有这些查询包含在一个函数或过程中。

谢谢

4

1 回答 1

1

Write a stored procedure and write all the queries there in that stored procedure after begin

于 2013-06-27T18:54:16.107 回答