PostgreSQL: format interval as minutes

后端 未结 3 1111
时光取名叫无心
时光取名叫无心 2020-12-29 19:31

When I subtract timestamps, the interval is in form DD:HH:MM:SS. How can I convert it all to minutes without extracting days and hours and multiplication/addition

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-29 20:06

    I don't actually think you can without doing a bunch of weirdness (like to_char) because minutes roll over at 59. Which is why you get:

    postgres=# select date_part('minutes', '65 minutes'::interval);
     date_part 
    -----------
             5
    (1 row)
    
    postgres=# select '65 minutes'::interval
    postgres-# ;
     interval 
    ----------
     01:05:00
    (1 row)
    

提交回复
热议问题