How do I convert an interval into a number of hours with postgres?

前端 未结 6 851
心在旅途
心在旅途 2020-11-28 22:31

Say I have an interval like

4 days 10:00:00

in postgres. How do I convert that to a number of hours (106 in this case?) Is there a function

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 22:44

    If you convert table field:

    1. Define the field so it contains seconds:

       CREATE TABLE IF NOT EXISTS test (
           ...
           field        INTERVAL SECOND(0)
       );
      
    2. Extract the value. Remember to cast to int other wise you can get an unpleasant surprise once the intervals are big:

      EXTRACT(EPOCH FROM field)::int

提交回复
热议问题