时间戳类型的表列没有毫秒?

时间:2014-01-02 05:52:46

标签: postgresql types timestamp create-table

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

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

1 个答案:

答案 0 :(得分:15)

指定精度:

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"是表字段的错误名称(我理解这是示例)。任何字段名称都应具有特定的语义。

相关问题