Abhijeet Gulve Abhijeet Gulve - 1 year ago 101
SQL Question

how to convert integer minutes to interval in postgres

I'm trying to convert minutes which are in integer to interval in postgres

Is their any function that will help me to convert it to interval or should i have divide it by 60 and get the final result

20 minutes will be like 00:20:00 as result

Answer Source

you can concat that integer with ' minutes':

t=# with i as (
  select 20::int n
select concat(n,' minutes')::interval 
from i;
(1 row)

Time: 1.220 ms


Or: interval '1' minute * n as a_horse_with_no_name says

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download