CREATE OR REPLACE FUNCTION timestamp_to_datestr(date BIGINT) RETURNS VARCHAR AS $BODY$ --由時間戳轉換成日期字符串 參數形如:1323083400000 轉換後爲2011-12-05 19:10:00 DECLARE result VARCHAR; BEGIN result := to_char((TIMESTAMP WITHOUT TIME ZONE 'epoch' + (date/1000) * INTERVAL '1 second' + interval '8 hour'),'YYYY-MM-DD HH24:MI:SS'); RETURN result; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE;
select update_date,timestamp_to_datestr(create_date),create_date from test;