在postgresql中为表创建指定字段的默认值

问题描述:

以下是我的表设计:

CREATE TABLE "x"."y"(
    "z" timestamp NOT NULL,
    "a" Timestamp NOT NULL DEFAULT z + 18 months,
)
WITH (OIDS=FALSE)
;

如何指定'a'的默认值?

How do I specify the default value of 'a'?

我可以在创建表格时指定它吗?

Can I specify this at the time of the table creation?

p> As postgresql文档声明

As postgresql documentation states


DEFAULT子句为其列定义出现的列分配一个默认数据值。该值是任何无变量表达式(子查询和对当前表中其他列的交叉引用不允许)。默认表达式的数据类型必须与列的数据类型匹配。

The DEFAULT clause assigns a default data value for the column whose column definition it appears within. The value is any variable-free expression (subqueries and cross-references to other columns in the current table are not allowed). The data type of the default expression must match the data type of the column.

规则( http://www.postgresql.org/docs/9.4/static /rules-update.html