Postgres时间戳到unix时间(以毫秒为单位)作为bigint



如何让以下代码段在postgres:中工作

ALTER TABLE mytable
ADD COLUMN create_time_utc bigint not null
DEFAULT (now() at time zone 'utc');

我希望新列create_time_utc是以毫秒为单位的unix时间(即自1970年1月1日unix epoch以来的毫秒数)。

我知道我需要将postgres timestamp转换为bigint,但我不确定如何做到这一点。

extract(epoch

alter table mytable
add column create_time_utc bigint not null
default (extract(epoch from now()) * 1000);

http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT

相关内容

最新更新