在postgresql中为表创建指定字段的默认值 [英] Specifying default value for a field for table creation in postgresql

查看:9374
本文介绍了在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

这篇关于在postgresql中为表创建指定字段的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆