How to map the PostgreSQL Interval column type in Hibernate?

后端 未结 5 1803
耶瑟儿~
耶瑟儿~ 2020-12-16 14:45

Under PostgreSQL, I\'m using PersistentDuration for the mapping between the sql type interval & duration but it doesn\'t work.

Another user found th

5条回答
  •  無奈伤痛
    2020-12-16 15:31

    PostgreSQL has a date_part / extract function which you can use to return different fields, epoch being one of them. When extracting the epoch from an interval, you receive the number of seconds contained in the interval, and from there you can convert however you wish. I lost my experience with Hibernate, but you can do it this way:

    SELECT
        average_interval_between_airings
      , date_part('epoch', average_interval_between_airings) / 60 as minutes
      , date_part('epoch', average_interval_between_airings) as seconds
    FROM shows;
    

提交回复
热议问题