Postgres比较时间戳和长Unix时间戳 [英] Postgres compare timestamp with long unix timestamp
本文介绍了Postgres比较时间戳和长Unix时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在要在SQL查询中放置条件的表中有一个timestamp属性,其中条件值是unix时间戳(即数字long值)。
I have a timestamp attribute in a table on which I want to place a condition in a sql query where the condition value is a unix timestamp (i.e. numeric long value).
[...] table.timestampattr > 6456454654 [...]
我该怎么做?
推荐答案
您可以使用 extract(来自...的时期)
从任何PostgreSQL获取Unix时间戳。时间和日期类型(请参见手册中的日期/时间函数) 。
You can use extract(epoch from ...)
to get a Unix timestamp from any of the PostgreSQL time and date types (see Date/Time functions in manual).
因此您的查询片段可以写成:
So your query fragment could be written:
[...] extract(epoch from table.timestampattr) > 6456454654 [...]
或者, to_timestamp
函数执行相反的转换,因此您还可以编写:
Alternatively, the to_timestamp
function performs the opposite conversion, so you could also write:
[...] table.timestampattr > to_timestamp(6456454654) [...]
这篇关于Postgres比较时间戳和长Unix时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文