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

编程入门 行业动态 更新时间:2024-10-07 20:30:31
本文介绍了在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.

规则( www.postgresql/docs/9.4/static /rules-update.html )

更多推荐

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

本文发布于:2023-10-16 14:01:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497776.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   中为   默认值   postgresql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!