PostgreSQL - 如何将数字字段中的秒数转换为HH:MM:SS [英] PostgreSQL - How to convert seconds in a numeric field to HH:MM:SS

查看:182
本文介绍了PostgreSQL - 如何将数字字段中的秒数转换为HH:MM:SS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PostgreSQL的新手(我一直在使用MS SQL多年),需要将一个数字列转换成HH:MM:SS格式的时间。

I'm new to PostgreSQL (I have been using MS SQL for many years) and need to convert a numeric column which contains a time in seconds to HH:MM:SS format.

我有谷歌,发现 to_char(interval'1000s','HH24:MI:SS')的作品,所以我试图用我的字段名称:

I have Googled and found that to_char(interval '1000s', 'HH24:MI:SS') works so I am attempting to use this with my field name:

to_char(fieldname,'HH24:MI:SS')给出错误不能一起使用S和PL/MI/SG/PR

to_char(fieldname :: interval,'HH24:MI:SS')给出错误不能将类型数字转换为间隔

任何人都可以告诉我我出错的地方?

Can anyone show me where I am going wrong?

推荐答案

SELECT  TO_CHAR('1000 second'::interval, 'HH24:MI:SS')

或在您的情况下

SELECT  TO_CHAR((mycolumn || ' second')::interval, 'HH24:MI:SS')
FROM    mytable

这篇关于PostgreSQL - 如何将数字字段中的秒数转换为HH:MM:SS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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