我是 PostgreSQL 的新手(我使用 MS SQL 多年),需要将包含以秒为单位的时间的数字列转换为 HH:MM:SS 格式。
我用 Google 搜索了一下,发现 to_char(interval '1000s', 'HH24:MI:SS')
有效,所以我尝试将它与我的字段名称一起使用:
to_char(fieldname, 'HH24:MI:SS')
给出错误 cannot use "S"and "PL"/"MI"/"SG"/"PR"together
to_char(fieldname::interval, 'HH24:MI:SS')
给出错误 cannot cast type numeric to interval
谁能告诉我哪里出错了?
最佳答案
SELECT TO_CHAR('1000 second'::interval, 'HH24:MI:SS')
或者,在你的情况下
SELECT TO_CHAR((mycolumn || ' second')::interval, 'HH24:MI:SS')
FROM mytable
关于datetime - PostgreSQL - 如何将数字字段中的秒数转换为 HH :MM:SS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2905692/