Postgres INTERVAL using value from table

后端 未结 3 1305
余生分开走
余生分开走 2020-12-18 14:00

If I want to add 5 days to a date, I can do it using the INTERVAL function:

select create_ts + interval \'5 days\' from abc_company;
         


        
3条回答
  •  天涯浪人
    2020-12-18 14:13

    Simply multiply the value with an interval:

    select create_ts + num_of_day * interval '1' day 
    from abc_company;
    

    Since Postgres 9.4 this is easier done using the make_interval() function:

    select create_ts + make_interval(days => num_of_day)
    from abc_company;
    

提交回复
热议问题