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

sun*_*ant 8 postgresql

如何在postgres中使用以下代码段:

ALTER TABLE mytable
ADD COLUMN create_time_utc bigint not null
DEFAULT (now() at time zone 'utc');
Run Code Online (Sandbox Code Playgroud)

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

我知道我需要将postgres转换timestamp为bigint,但我不知道该怎么做.

Clo*_*eto 16

extract(epoch

alter table mytable
add column create_time_utc bigint not null
default (extract(epoch from now()) * 1000);
Run Code Online (Sandbox Code Playgroud)

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