Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
7bbdb078
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7bbdb078
编写于
1月 09, 2005
作者:
T
Tom Lane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update discussion of ALTER TABLE ADD COLUMN, per Michael Fuhr.
上级
0549de06
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
13 deletion
+17
-13
doc/src/sgml/ddl.sgml
doc/src/sgml/ddl.sgml
+17
-13
未找到文件。
doc/src/sgml/ddl.sgml
浏览文件 @
7bbdb078
<!-- $PostgreSQL: pgsql/doc/src/sgml/ddl.sgml,v 1.3
6 2005/01/08 01:44:05
tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/ddl.sgml,v 1.3
7 2005/01/09 17:47:30
tgl Exp $ -->
<chapter id="ddl">
<title>Data Definition</title>
...
...
@@ -1279,23 +1279,22 @@ WHERE c.altitude > 500 and c.tableoid = p.oid;
<programlisting>
ALTER TABLE products ADD COLUMN description text;
</programlisting>
The new column
will initially be filled with null values in the
existing rows of the table
.
The new column
is initially filled with whatever default
value is given (null if you don't specify a <literal>DEFAULT</> clause)
.
</para>
<para>
You can also define
a constraint
on the column at the same time,
You can also define
constraints
on the column at the same time,
using the usual syntax:
<programlisting>
ALTER TABLE products ADD COLUMN description text CHECK (description <> '');
</programlisting>
A new column cannot have a not-null constraint since the column
initially has to contain null values. But you can add a not-null
constraint later. Also, you cannot define a default value on a
new column. According to the SQL standard, this would have to
fill the new columns in the existing rows with the default value,
which is not implemented yet. But you can adjust the column
default later on.
In fact all the options that can be applied to a column description
in <command>CREATE TABLE</> can be used here. Keep in mind however
that the default value must satisfy the given constraints, or the
<literal>ADD</> will fail. Alternatively, you can add
constraints later (see below) after you've filled in the new column
correctly.
</para>
</sect2>
...
...
@@ -1390,12 +1389,17 @@ ALTER TABLE products ALTER COLUMN product_no DROP NOT NULL;
<programlisting>
ALTER TABLE products ALTER COLUMN price SET DEFAULT 7.77;
</programlisting>
Note that this doesn't affect any existing rows in the table, it
just changes the default for future <command>INSERT</> commands.
</para>
<para>
To remove any default value, use
<programlisting>
ALTER TABLE products ALTER COLUMN price DROP DEFAULT;
</programlisting>
This is equivalent to setting the default to null
, at least in
<productname>PostgreSQL</>.
As a consequence, it is not an error
This is equivalent to setting the default to null
.
As a consequence, it is not an error
to drop a default where one hadn't been defined, because the
default is implicitly the null value.
</para>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录