问题描述
我是Postgresql bot的新手,而不是sql。我有一个需要从中读取值的表,其中一列是unix时间戳,我想将其转换为更易读的格式,因此我发现了这一点:
I am new to postgresql bot not to sql in general. I have a table that I need to read values from, on of the columns is a unix timestamp that I want to convert in to a more human readable format thus I found this:
SELECT lt,dw,up,to_char(uxts, 'YYYY-MM-DD HH24:MI:SS')
from products;
但这会产生错误:
错误:多个小数点
But that produces an error:ERROR: multiple decimal points
我在这里迷路了。我相信有人可以教我如何做。该文档对我来说还不清楚。 PostgreSQL 9.5是数据库。
I am lost here. I am sure someone can show me how to do it. The documentation isn't that clear to me. Postgresql 9.5 is the database.
推荐答案
to_char()
转换数字,日期或时间戳记转换为字符串,而不是相反。
to_char()
converts a number, date or timestamp to a string, not the other way round.
您要
在您的列上应用该函数
So just apply that function on your column
SELECT lt,dw,up,to_timestamp(uxts) as uxts
from products;
这假定uxts是某种数字数据类型( integer
, bigint
或双精度
)
This assumes that uxts is some kind of number data type (integer
, bigint
or double precision
)
这篇关于如何将Unix纪元转换为时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!