如何在postgres中将整数分钟转换为间隔 [英] how to convert integer minutes to interval in postgres

查看:134
本文介绍了如何在postgres中将整数分钟转换为间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将整数转换为postgres中的间隔

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

它们是可以帮助我将其转换为时间间隔的任何函数,还是应该将其除以60并获得最终结果

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 

推荐答案

最快的方法是使用make_interval

make_interval(years int DEFAULT 0, months int DEFAULT 0, weeks int DEFAULT 0, days int DEFAULT 0, hours int DEFAULT 0, mins int DEFAULT 0, secs double precision DEFAULT 0.0)

所以看起来像这样(由@Teddy建议)

So it looks like this (as suggested by @Teddy)

SELECT make_interval(mins => 20);

SELECT make_interval(0,0,0,0,0,20);

并不是说这是最干净的,如果速度不是问题,我更喜欢使用*方法@a_horse_with_no_name

Not to say that's the cleanest, if speed isn't an issue I prefer the * method @a_horse_with_no_name mentioned

SELECT 20 * '1 minute'::interval;

这篇关于如何在postgres中将整数分钟转换为间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆