如何让以下代码段在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