I am actually surprised that postgres does not have a builtin function to deal
with unix timestamps. After all it does run on linux which does use unix
timestamps. So it must be a common problem. Here is a quick solution.

CREATE OR REPLACE FUNCTION parseunixtimestamp(int)
        RETURNS timestamp AS
                'SELECT TIMESTAMP ''epoch'' + $1 * INTERVAL ''1 second'''

Now you can use it in select or insert statements. Like this

INSERT INTO TABLE (name, createdon) VALUES("a value", parseunixtimestamp(55436437))

If you need to you can remove it again later by running

DROP FUNCTION parseunixtimestamp(integer);

Did You find this page useful?

Yes No

Last Modified: 18 February 2017

Releated Posts

2012-02-02 - Postgres - Convert unix timestamp