Best way to store time above 24:00:00 in postgresql?

后端 未结 2 691
广开言路
广开言路 2021-01-14 00:42

I\'m storing GTFS feeds into a SQL database and some times are expected to be stored above the 24:00:00 cap on time values. For example, some trains run at 12:30AM, but are

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-14 00:49

    I'd store two fields:

    departure_time timestamp with time zone,
    service_date date
    

    Departure time would be calculated like this:

     => select '2015-07-08'::timestamptz+'24:30'::interval;
     2015-07-09 00:30:00+02
    

    This way:

    • you have a normal moment of time field for sorting events;
    • you'd not loose service date information;
    • you'd be able to calculate back the original GTFS data if needed.

提交回复
热议问题