Answer a question

I am new to PostgreSQL sql and now working on an already existing database. I have a column called value in a table and it contains datetime stamp in seconds. So I am looking for way I can convert those seconds to yyyy-mm-dd hh:mm:ss in a Postgres database. I tried the following:

SELECT  TO_CHAR('1444646136079 second'::interval, 'yyyy-mm-dd HH24:MI:SS')

1444646136079 is the value I would like to convert But I am getting the following error:

ERROR: interval field value out of range: "1444646136079 second"

Answers

An interval is not a "timestamp".

The to_timestamp() function accepts seconds as an input and can convert that to a proper timestamp. I believe your 1444646136079 is in fact milli seconds, not seconds:

select to_char(to_timestamp(1444646136079 / 1000), 'yyyy-mm-dd HH24:MI:SS')

returns:

2015-10-12 12:35:36
Logo

PostgreSQL社区为您提供最前沿的新闻资讯和知识内容

更多推荐