【问题标题】:Creating a default timestamp in PostgreSQL在 PostgreSQL 中创建默认时间戳
【发布时间】:2018-01-13 18:39:09
【问题描述】:

我想在现有表中创建默认时间戳列。

我的第一个查询是

"ALTER TABLE {table_name} ADD COLUMN modifiedDate timestamp without time zone"

这有效并成功添加了列。

但是第二个查询

ALTER TABLE {table_name} ALTER modifiedDate SET DEFAULT '2001-01-01 00:00:00'::timestamp without time zone;

未能更新列上的所有行以包含该时间戳。

我在关注this SO 帖子。

我也试过一个查询

"ALTER TABLE {table_name} ADD COLUMN modifiedDate timestamp without time zone" SET DEFAULT '2001-01-01 00:00:00'::timestamp without time zone;

但这给出了错误syntax error at or near "00"

【问题讨论】:

    标签: postgresql datetime time


    【解决方案1】:

    愚蠢的错误。

    ALTER TABLE {table_name} ADD COLUMN modifiedDate timestamp without time zone NOT NULL DEFAULT '2001-01-01 00:00:00'::timestamp without time zone;

    SET 不应该在一个衬里。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-14
      • 2013-05-29
      • 1970-01-01
      • 2016-12-18
      • 2013-06-20
      • 2016-03-28
      • 2016-04-07
      • 1970-01-01
      相关资源
      最近更新 更多