Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
7bbdb078
Commit
7bbdb078
authored
20 years ago
by
Tom Lane
Browse files
Options
Downloads
Patches
Plain Diff
Update discussion of ALTER TABLE ADD COLUMN, per Michael Fuhr.
parent
0549de06
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/src/sgml/ddl.sgml
+17
-13
17 additions, 13 deletions
doc/src/sgml/ddl.sgml
with
17 additions
and
13 deletions
doc/src/sgml/ddl.sgml
+
17
−
13
View file @
7bbdb078
<!-- $PostgreSQL: pgsql/doc/src/sgml/ddl.sgml,v 1.3
6
2005/01/0
8 01:44:05
tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/ddl.sgml,v 1.3
7
2005/01/0
9 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 constraint
s
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>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment