Issue
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 [...]
How can I do this?
Solution
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 [...]
Alternatively, the to_timestamp function performs the opposite conversion, so you could also write:
[...] table.timestampattr > to_timestamp(6456454654) [...]
Answered By - IMSoP Answer Checked By - Pedro (sql.easybugfix Volunteer)
Post a Comment
Post a Comment