How to insert Unix time as PostgreSQL timestamp

July 22, 2012

Quick googling turned up lots of insane (or just outdated) type conversion advice, while the answer is very simple: use standard function to_timestamp(), like this:

INSERT INTO foo VALUES ( to_timestamp(1342986162) )

Reverse operation is equally easy:

SELECT EXTRACT( EPOCH FROM now() )

Hopefully next time when I forget how to do that, I’ll remember to look for it here.

tags:
posted in Software development by nohuhu

Follow comments via the RSS Feed | Leave a comment | Trackback URL

Leave Your Comment

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org