在PostgreSQL中创建默认时间戳

在PostgreSQL中创建默认时间戳

问题描述:

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

我的第一个查询是

"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"

愚蠢的错误。

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不应该在一个衬垫。