【问题标题】:Table column of type timestamp without milliseconds?没有毫秒的时间戳类型的表列?
【发布时间】:2014-01-02 05:52:46
【问题描述】:

我想创建一个没有毫秒的表有(id,时间)和时间(没有时区的时间戳)。
而且我还想在默认情况下插入当前时间。

CREATE TABLE ddd (
    id          serial not null,         
    time        timestamp without time zone default now()
    );

【问题讨论】:

标签: postgresql types timestamp create-table


【解决方案1】:

指定精度:

postgres=# CREATE TABLE foo(a timestamp(0));
CREATE TABLE
postgres=# INSERT INTO foo VALUES(CURRENT_TIMESTAMP);
INSERT 0 1
postgres=# SELECT * FROM foo;
          a          
---------------------
 2014-01-02 07:26:23
(1 row)

小提示 - "time" 是表字段的错误名称(我知道这是示例)。任何字段名称都应具有特定的语义。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-20
    • 1970-01-01
    • 2019-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-25
    相关资源
    最近更新 更多