问题
Following is my table design:
CREATE TABLE "x"."y"(
    "z" timestamp NOT NULL,
    "a" Timestamp NOT NULL DEFAULT z + 18 months,
)
WITH (OIDS=FALSE)
;
How do I specify the default value of 'a'?
Can I specify this at the time of the table creation?
回答1:
As postgresql documentation states
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.
It's better to use e.g. rules (http://www.postgresql.org/docs/9.4/static/rules-update.html)
来源:https://stackoverflow.com/questions/30621482/specifying-default-value-for-a-field-for-table-creation-in-postgresql