【问题标题】:How to add integer column with default of unix timestamp (epoch) in PostgreSQL?如何在 PostgreSQL 中添加默认为 unix 时间戳(纪元)的整数列?
【发布时间】:2010-11-03 23:32:23
【问题描述】:

这不起作用:

create table event (
...
time int default date_part('epoch', timestamp 'now'),
...
);

【问题讨论】:

    标签: datetime postgresql epoch


    【解决方案1】:

    我不是 postgresql 专家,但这个不应该工作

    time int default date_part('epoch', now())
    

    【讨论】:

    • 或者使用更现代的语法 - “atime INTEGER DEFAULT EXTRACT(EPOCH FROM CURRENT_TIMESTAMP)”。
    • 我的编辑器自动将上面的评论更改为 date_part('epoch'::text, now()) ,所以我猜那是 2020 年的现代版本。
    猜你喜欢
    • 2020-05-20
    • 2021-12-14
    • 2023-02-26
    • 2021-07-09
    • 1970-01-01
    • 2012-03-10
    • 1970-01-01
    • 1970-01-01
    • 2011-03-24
    相关资源
    最近更新 更多