Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit853153c

Browse files
committed
ALTER DOMAIN .. SET / DROP NOT NULL
ALTER DOMAIN .. SET / DROP DEFAULTALTER DOMAIN .. ADD / DROP CONSTRAINTNew files:- doc/src/sgml/ref/alter_domain.sgmlRod Taylor
1 parent36580c8 commit853153c

File tree

22 files changed

+1526
-262
lines changed

22 files changed

+1526
-262
lines changed

‎doc/src/sgml/ref/allfiles.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.49 2002/09/07 16:49:50 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.50 2002/12/06 03:28:27 momjian Exp $
33
PostgreSQL documentation
44
Complete list of usable sgml source files in this directory.
55
-->
@@ -38,6 +38,7 @@ Complete list of usable sgml source files in this directory.
3838
<!-- SQL commands -->
3939
<!entity abort system "abort.sgml">
4040
<!entity alterDatabase system "alter_database.sgml">
41+
<!entity alterDomain system "alter_domain.sgml">
4142
<!entity alterGroup system "alter_group.sgml">
4243
<!entity alterTable system "alter_table.sgml">
4344
<!entity alterTrigger system "alter_trigger.sgml">

‎doc/src/sgml/ref/alter_domain.sgml

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
<!--
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_domain.sgml,v 1.1 2002/12/06 03:28:27 momjian Exp $
3+
PostgreSQL documentation
4+
-->
5+
6+
<refentry id="SQL-ALTERDOMAIN">
7+
<refmeta>
8+
<refentrytitle id="sql-alterdomain-title">ALTER DOMAIN</refentrytitle>
9+
<refmiscinfo>SQL - Language Statements</refmiscinfo>
10+
</refmeta>
11+
<refnamediv>
12+
<refname>
13+
ALTER DOMAIN
14+
</refname>
15+
<refpurpose>
16+
change the definition of a table
17+
</refpurpose>
18+
</refnamediv>
19+
<refsynopsisdiv>
20+
<refsynopsisdivinfo>
21+
<date>2002-11-27</date>
22+
</refsynopsisdivinfo>
23+
<synopsis>
24+
ALTER DOMAIN <replaceable class="PARAMETER">domain</replaceable>
25+
{ SET DEFAULT <replaceable class="PARAMETER">value</replaceable> | DROP DEFAULT }
26+
ALTER DOMAIN <replaceable class="PARAMETER">domain</replaceable>
27+
{ SET | DROP } NOT NULL
28+
ALTER DOMAIN <replaceable class="PARAMETER">domain</replaceable>
29+
ADD <replaceable class="PARAMETER">domain_constraint</replaceable>
30+
ALTER DOMAIN <replaceable class="PARAMETER">domain</replaceable>
31+
DROP CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> [ RESTRICT | CASCADE ]
32+
</synopsis>
33+
34+
<refsect2 id="R2-SQL-ALTERDOMAIN-1">
35+
<refsect2info>
36+
<date>2002-11-27</date>
37+
</refsect2info>
38+
<title>
39+
Inputs
40+
</title>
41+
<para>
42+
<variablelist>
43+
44+
<varlistentry>
45+
<term><replaceable class="PARAMETER"> domain </replaceable></term>
46+
<listitem>
47+
<para>
48+
The name (possibly schema-qualified) of an existing domain to
49+
alter.
50+
</para>
51+
</listitem>
52+
</varlistentry>
53+
54+
<varlistentry>
55+
<term><replaceable class="PARAMETER"> domain_constraint </replaceable></term>
56+
<listitem>
57+
<para>
58+
New domain constraint for the domain.
59+
</para>
60+
</listitem>
61+
</varlistentry>
62+
63+
<varlistentry>
64+
<term><replaceable class="PARAMETER"> constraint_name </replaceable></term>
65+
<listitem>
66+
<para>
67+
Name of an existing constraint to drop.
68+
</para>
69+
</listitem>
70+
</varlistentry>
71+
72+
<varlistentry>
73+
<term>CASCADE</term>
74+
<listitem>
75+
<para>
76+
Automatically drop objects that depend constraint.
77+
</para>
78+
</listitem>
79+
</varlistentry>
80+
81+
<varlistentry>
82+
<term>RESTRICT</term>
83+
<listitem>
84+
<para>
85+
Refuse to drop the constraint if there are any dependent
86+
objects. This is the default behavior.
87+
</para>
88+
</listitem>
89+
</varlistentry>
90+
91+
</variablelist>
92+
</para>
93+
</refsect2>
94+
95+
<refsect2 id="R2-SQL-ALTERDOMAIN-2">
96+
<refsect2info>
97+
<date>1998-04-15</date>
98+
</refsect2info>
99+
<title>
100+
Outputs
101+
</title>
102+
<para>
103+
104+
<variablelist>
105+
<varlistentry>
106+
<term><computeroutput>ALTER DOMAIN</computeroutput></term>
107+
<listitem>
108+
<para>
109+
Message returned from domain alteration.
110+
</para>
111+
</listitem>
112+
</varlistentry>
113+
114+
<varlistentry>
115+
<term><computeroutput>ERROR</computeroutput></term>
116+
<listitem>
117+
<para>
118+
Message returned if domain is not available.
119+
</para>
120+
</listitem>
121+
</varlistentry>
122+
</variablelist>
123+
</para>
124+
</refsect2>
125+
</refsynopsisdiv>
126+
127+
<refsect1 id="R1-SQL-ALTERDOMAIN-1">
128+
<refsect1info>
129+
<date>2002-11-27</date>
130+
</refsect1info>
131+
<title>
132+
Description
133+
</title>
134+
<para>
135+
<command>ALTER DOMAIN</command> changes the definition of an existing domain.
136+
There are several sub-forms:
137+
</para>
138+
139+
<variablelist>
140+
<varlistentry>
141+
<term>SET/DROP DEFAULT</term>
142+
<listitem>
143+
<para>
144+
These forms set or remove the default value for a column. Note
145+
that defaults only apply to subsequent <command>INSERT</command>
146+
commands; they do not cause rows already in a table using the domain.
147+
</para>
148+
</listitem>
149+
</varlistentry>
150+
151+
<varlistentry>
152+
<term>SET/DROP NOT NULL</term>
153+
<listitem>
154+
<para>
155+
These forms change whether a domain is marked to allow NULL
156+
values or to reject NULL values. You may only <literal>SET NOT NULL</>
157+
when the tables using the domain contain no null values in the domain
158+
based column.
159+
</para>
160+
</listitem>
161+
</varlistentry>
162+
163+
<varlistentry>
164+
<term>ADD <replaceable class="PARAMETER">domain_constraint</replaceable></term>
165+
<listitem>
166+
<para>
167+
This form adds a new constraint to a table using the same syntax as
168+
<xref linkend="SQL-CREATEDOMAIN" endterm="SQL-CREATEDOMAIN-TITLE">.
169+
</para>
170+
</listitem>
171+
</varlistentry>
172+
173+
<varlistentry>
174+
<term>DROP CONSTRAINT</term>
175+
<listitem>
176+
<para>
177+
This form drops constraints on a domain.
178+
</para>
179+
</listitem>
180+
</varlistentry>
181+
182+
</variablelist>
183+
184+
<para>
185+
You must own the domain to use <command>ALTER DOMAIN</>; except for
186+
<command>ALTER TABLE OWNER</>, which may only be executed by a superuser.
187+
</para>
188+
</refsect1>
189+
190+
<refsect1 id="R1-SQL-ALTERDOMAIN-2">
191+
<title>
192+
Usage
193+
</title>
194+
<para>
195+
To add a NOT NULL constraint to a column:
196+
<programlisting>
197+
ALTER DOMAIN zipcode SET NOT NULL;
198+
</programlisting>
199+
To remove a NOT NULL constraint from a column:
200+
<programlisting>
201+
ALTER DOMAIN zipcode DROP NOT NULL;
202+
</programlisting>
203+
</para>
204+
205+
<para>
206+
To add a check constraint to a table:
207+
<programlisting>
208+
ALTER DOMAIN zipcode ADD CONSTRAINT zipchk CHECK (char_length(VALUE) = 5);
209+
</programlisting>
210+
</para>
211+
212+
<para>
213+
To remove a check constraint from a table and all its children:
214+
<programlisting>
215+
ALTER DOMAIN zipcode DROP CONSTRAINT zipchk;
216+
</programlisting>
217+
</para>
218+
</refsect1>
219+
220+
</refentry>
221+
222+
<!-- Keep this comment at the end of the file
223+
Local variables:
224+
mode: sgml
225+
sgml-omittag:nil
226+
sgml-shorttag:t
227+
sgml-minimize-attributes:nil
228+
sgml-always-quote-attributes:t
229+
sgml-indent-step:1
230+
sgml-indent-data:t
231+
sgml-parent-document:nil
232+
sgml-default-dtd-file:"../reference.ced"
233+
sgml-exposed-tags:nil
234+
sgml-local-catalogs:"/usr/lib/sgml/catalog"
235+
sgml-local-ecat-files:nil
236+
End:
237+
-->

‎doc/src/sgml/reference.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- reference.sgml
2-
$Header: /cvsroot/pgsql/doc/src/sgml/reference.sgml,v 1.38 2002/09/08 02:33:08 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/reference.sgml,v 1.39 2002/12/06 03:28:27 momjian Exp $
33

44
PostgreSQL Reference Manual
55
-->
@@ -47,6 +47,7 @@ PostgreSQL Reference Manual
4747

4848
&abort;
4949
&alterDatabase;
50+
&alterDomain;
5051
&alterGroup;
5152
&alterTable;
5253
&alterTrigger;

‎src/backend/catalog/dependency.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.14 2002/12/04 20:00:37 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.15 2002/12/06 03:28:27 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -36,6 +36,7 @@
3636
#include"commands/proclang.h"
3737
#include"commands/schemacmds.h"
3838
#include"commands/trigger.h"
39+
#include"commands/typecmds.h"
3940
#include"lib/stringinfo.h"
4041
#include"miscadmin.h"
4142
#include"optimizer/clauses.h"

‎src/backend/catalog/pg_constraint.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_constraint.c,v 1.8 2002/11/15 02:50:05 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_constraint.c,v 1.9 2002/12/06 03:28:27 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -199,6 +199,7 @@ CreateConstraintEntry(const char *constraintName,
199199

200200
domobject.classId=RelOid_pg_type;
201201
domobject.objectId=domainId;
202+
domobject.objectSubId=0;
202203

203204
recordDependencyOn(&conobject,&domobject,DEPENDENCY_AUTO);
204205
}
@@ -496,15 +497,16 @@ RemoveConstraintById(Oid conId)
496497
HeapTupletypTup;
497498
ScanKeyDatatypKey[1];
498499
SysScanDesctypScan;
500+
intnkeys=0;
499501

500502
typRel=heap_openr(TypeRelationName,RowExclusiveLock);
501503

502-
ScanKeyEntryInitialize(&typKey[0],0x0,
503-
Anum_pg_constraint_contypid,F_OIDEQ,
504+
ScanKeyEntryInitialize(&typKey[nkeys++],0x0,
505+
ObjectIdAttributeNumber,F_OIDEQ,
504506
ObjectIdGetDatum(con->contypid));
505507

506508
typScan=systable_beginscan(typRel,TypeOidIndex, true,
507-
SnapshotNow,1,typKey);
509+
SnapshotNow,nkeys,typKey);
508510

509511
typTup=systable_getnext(typScan);
510512

@@ -517,6 +519,11 @@ RemoveConstraintById(Oid conId)
517519
/* Keep lock on domain type until end of xact */
518520
heap_close(typRel,NoLock);
519521
}
522+
else
523+
{
524+
elog(ERROR,"RemoveConstraintById: Constraint %u is not a known type",
525+
conId);
526+
}
520527

521528
/* Fry the constraint itself */
522529
simple_heap_delete(conDesc,&tup->t_self);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp