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''' LANGUAGE SQL;
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?
Thanks for the feeback. Please consider sharing with others.