Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d3788c3

Browse files
committed
Add DOMAIN support. Includes manual pages and regression tests, from
Rod Taylor.
1 parent 525b193 commit d3788c3

36 files changed

+1805
-286
lines changed

doc/src/sgml/catalogs.sgml

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Documentation of the system catalogs, directed toward PostgreSQL developers
3-
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.33 2002/03/07 16:35:32 momjian Exp $
3+
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.34 2002/03/19 02:18:10 momjian Exp $
44
-->
55

66
<chapter id="catalogs">
@@ -2510,6 +2510,53 @@
25102510
</para></entry>
25112511
</row>
25122512

2513+
<row>
2514+
<entry>typbasetype</entry>
2515+
<entry><type>oid</type></entry>
2516+
<entry></entry>
2517+
<entry><para>
2518+
<structfield>typbasetype</structfield> is the type that this one is based
2519+
on. Normally references the domains parent type, and is 0 otherwise.
2520+
</para></entry>
2521+
</row>
2522+
2523+
<row>
2524+
<entry>typnotnull</entry>
2525+
<entry><type>boolean</type></entry>
2526+
<entry></entry>
2527+
<entry><para>
2528+
<structfield>typnotnull</structfield> represents a NOT NULL
2529+
constraint on a type. Used for domains only.
2530+
</para></entry>
2531+
</row>
2532+
2533+
<row>
2534+
<entry>typmod</entry>
2535+
<entry><type>integer</type></entry>
2536+
<entry></entry>
2537+
<entry><para>
2538+
<structfield>typmod</structfield> records type-specific data
2539+
supplied at table creation time (for example, the maximum
2540+
length of a <type>varchar</type> column). It is passed to
2541+
type-specific input and output functions as the third
2542+
argument. The value will generally be -1 for types that do not
2543+
need typmod. This data is copied to
2544+
<structfield>pg_attribute.atttypmod</structfield> on creation
2545+
of a table using a domain as it's field type.
2546+
</para></entry>
2547+
</row>
2548+
2549+
<row>
2550+
<entry>typdefaultbin</entry>
2551+
<entry><type>text</type></entry>
2552+
<entry></entry>
2553+
<entry><para>
2554+
<structfield>typdefaultbin</structfield> is NULL for types without a
2555+
default value. If it's not NULL, it contains the internal string
2556+
representation of the default expression node.
2557+
</para></entry>
2558+
</row>
2559+
25132560
<row>
25142561
<entry>typdefault</entry>
25152562
<entry><type>text</type></entry>

doc/src/sgml/ref/allfiles.sgml

Lines changed: 3 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.35 2002/03/07 16:35:32 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.36 2002/03/19 02:18:12 momjian Exp $
33
PostgreSQL documentation
44
Complete list of usable sgml source files in this directory.
55
-->
@@ -52,6 +52,7 @@ Complete list of usable sgml source files in this directory.
5252
<!entity createAggregate system "create_aggregate.sgml">
5353
<!entity createConstraint system "create_constraint.sgml">
5454
<!entity createDatabase system "create_database.sgml">
55+
<!entity createDomain system "create_domain.sgml">
5556
<!entity createFunction system "create_function.sgml">
5657
<!entity createGroup system "create_group.sgml">
5758
<!entity createIndex system "create_index.sgml">
@@ -69,6 +70,7 @@ Complete list of usable sgml source files in this directory.
6970
<!entity delete system "delete.sgml">
7071
<!entity dropAggregate system "drop_aggregate.sgml">
7172
<!entity dropDatabase system "drop_database.sgml">
73+
<!entity dropDomain system "drop_domain.sgml">
7274
<!entity dropFunction system "drop_function.sgml">
7375
<!entity dropGroup system "drop_group.sgml">
7476
<!entity dropIndex system "drop_index.sgml">

doc/src/sgml/ref/comment.sgml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/comment.sgml,v 1.14 2002/03/07 16:35:33 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/comment.sgml,v 1.15 2002/03/19 02:18:12 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -25,15 +25,15 @@ PostgreSQL documentation
2525
<synopsis>
2626
COMMENT ON
2727
[
28-
[ DATABASE | INDEX | RULE | SEQUENCE | TABLE | TYPE | VIEW ] <replaceable class="PARAMETER">object_name</replaceable> |
28+
[ DATABASE | DOMAIN | INDEX | RULE | SEQUENCE | TABLE | TYPE | VIEW ] <replaceable class="PARAMETER">object_name</replaceable> |
2929
COLUMN <replaceable class="PARAMETER">table_name</replaceable>.<replaceable class="PARAMETER">column_name</replaceable> |
3030
AGGREGATE <replaceable class="PARAMETER">agg_name</replaceable> (<replaceable class="PARAMETER">agg_type</replaceable>) |
3131
FUNCTION <replaceable class="PARAMETER">func_name</replaceable> (<replaceable class="PARAMETER">arg1</replaceable>, <replaceable class="PARAMETER">arg2</replaceable>, ...) |
3232
OPERATOR <replaceable class="PARAMETER">op</replaceable> (<replaceable class="PARAMETER">leftoperand_type</replaceable> <replaceable class="PARAMETER">rightoperand_type</replaceable>) |
3333
TRIGGER <replaceable class="PARAMETER">trigger_name</replaceable> ON <replaceable class="PARAMETER">table_name</replaceable>
3434
] IS <replaceable class="PARAMETER">'text'</replaceable>
3535
</synopsis>
36-
36+
3737
<refsect2 id="R2-SQL-COMMENT-1">
3838
<refsect2info>
3939
<date>1999-10-25</date>
@@ -64,7 +64,7 @@ COMMENT ON
6464
</variablelist>
6565
</para>
6666
</refsect2>
67-
67+
6868
<refsect2 id="R2-SQL-COMMENT-2">
6969
<refsect2info>
7070
<date>1998-09-08</date>
@@ -99,7 +99,7 @@ COMMENT
9999
</title>
100100
<para>
101101
<command>COMMENT</command> stores a comment about a database object.
102-
Comments can be
102+
Comments can be
103103
easily retrieved with <command>psql</command>'s
104104
<command>\dd</command>, <command>\d+</command>, or <command>\l+</command>
105105
commands. Other user interfaces to retrieve comments can be built atop
@@ -141,6 +141,7 @@ COMMENT ON mytable IS 'This is my table.';
141141

142142
<programlisting>
143143
COMMENT ON DATABASE my_database IS 'Development Database';
144+
COMMENT ON DOMAIN my_domain IS 'Email Address Domain';
144145
COMMENT ON INDEX my_index IS 'Enforces uniqueness on employee id';
145146
COMMENT ON RULE my_rule IS 'Logs UPDATES of employee records';
146147
COMMENT ON SEQUENCE my_sequence IS 'Used to generate primary keys';
@@ -155,12 +156,12 @@ COMMENT ON TRIGGER my_trigger ON my_table IS 'Used for R.I.';
155156
</programlisting>
156157
</para>
157158
</refsect1>
158-
159+
159160
<refsect1 id="R1-SQL-COMMENT-3">
160161
<title>
161162
Compatibility
162163
</title>
163-
164+
164165
<refsect2 id="R2-SQL-COMMENT-4">
165166
<refsect2info>
166167
<date>1998-09-08</date>

doc/src/sgml/ref/create_domain.sgml

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
<!--
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.3 2002/03/19 02:18:13 momjian Exp $
3+
PostgreSQL documentation
4+
-->
5+
6+
<refentry id="SQL-CREATEDOMAIN">
7+
<refmeta>
8+
<refentrytitle id="sql-createdomian-title">
9+
CREATE DOMAIN
10+
</refentrytitle>
11+
<refmiscinfo>SQL - Language Statements</refmiscinfo>
12+
</refmeta>
13+
<refnamediv>
14+
<refname>
15+
CREATE DOMAIN
16+
</refname>
17+
<refpurpose>
18+
define a new domain
19+
</refpurpose>
20+
</refnamediv>
21+
<refsynopsisdiv>
22+
<refsynopsisdivinfo>
23+
<date>2002-02-24</date>
24+
</refsynopsisdivinfo>
25+
<synopsis>
26+
CREATE DOMAIN <replaceable class="parameter">domainname</replaceable> <replaceable class="parameter">data_type</replaceable> [ DEFAULT <replaceable>default_expr</> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [, ... ] ]
27+
[ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ]
28+
{ NOT NULL | NULL <!-- | UNIQUE | PRIMARY KEY |
29+
CHECK (<replaceable class="PARAMETER">expression</replaceable>) |
30+
REFERENCES <replaceable class="PARAMETER">reftable</replaceable> [ ( <replaceable class="PARAMETER">refcolumn</replaceable> ) ] [ MATCH FULL | MATCH PARTIAL ]
31+
[ ON DELETE <replaceable class="parameter">action</replaceable> ] [ ON UPDATE <replaceable class="parameter">action</replaceable> ] --> }
32+
<!-- [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ] -->
33+
</synopsis>
34+
35+
<refsect2 id="R2-SQL-CREATEDOMAIN-1">
36+
<refsect2info>
37+
<date>2002-02-24</date>
38+
</refsect2info>
39+
<title>
40+
Parameters
41+
</title>
42+
<para>
43+
44+
<variablelist>
45+
<varlistentry>
46+
<term><replaceable class="parameter">domainname</replaceable></term>
47+
<listitem>
48+
<para>
49+
The name of a domain to be created.
50+
</para>
51+
</listitem>
52+
</varlistentry>
53+
54+
<varlistentry>
55+
<term><replaceable class="PARAMETER">data_type</replaceable></term>
56+
<listitem>
57+
<para>
58+
The data type of the domain. This may include array specifiers.
59+
Refer to the <citetitle>User's Guide</citetitle> for further
60+
information about data types and arrays.
61+
</para>
62+
</listitem>
63+
</varlistentry>
64+
65+
<varlistentry>
66+
<term><literal>DEFAULT
67+
<replaceable>default_expr</replaceable></literal></term>
68+
<listitem>
69+
<para>
70+
The <literal>DEFAULT</> clause assigns a default data value for
71+
the column whose column definition it appears within. The value
72+
is any variable-free expression (subselects and cross-references
73+
to other columns in the current table are not allowed). The
74+
data type of the default expression must match the data type of the
75+
domain.
76+
</para>
77+
78+
<para>
79+
The default expression will be used in any insert operation that
80+
does not specify a value for the domain. If there is no default
81+
for a domain, then the default is NULL.
82+
</para>
83+
84+
<note>
85+
<para>
86+
The default of a column will be tested before that of the domain.
87+
</para>
88+
</note>
89+
</listitem>
90+
</varlistentry>
91+
92+
<varlistentry>
93+
<term><literal>CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable></literal></term>
94+
<listitem>
95+
<para>
96+
An optional name for a domain. If not specified,
97+
the system generates a name.
98+
</para>
99+
</listitem>
100+
</varlistentry>
101+
102+
<varlistentry>
103+
<term><literal>NOT NULL</></term>
104+
<listitem>
105+
<para>
106+
The column is not allowed to contain NULL values. This is
107+
equivalent to the column constraint <literal>CHECK (<replaceable
108+
class="PARAMETER">column</replaceable> NOT NULL)</literal>.
109+
</para>
110+
</listitem>
111+
</varlistentry>
112+
113+
<varlistentry>
114+
<term><literal>NULL</></term>
115+
<listitem>
116+
<para>
117+
The column is allowed to contain NULL values. This is the default.
118+
</para>
119+
120+
<para>
121+
This clause is only available for compatibility with
122+
non-standard SQL databases. Its use is discouraged in new
123+
applications.
124+
</para>
125+
</listitem>
126+
</varlistentry>
127+
128+
</variablelist>
129+
</para>
130+
</refsect2>
131+
132+
<refsect2 id="R2-SQL-CREATEDOMAIN-2">
133+
<refsect2info>
134+
<date>2002-02-24</date>
135+
</refsect2info>
136+
<title>
137+
Outputs
138+
</title>
139+
<para>
140+
141+
<variablelist>
142+
<varlistentry>
143+
<term><computeroutput>
144+
CREATE DOMAIN
145+
</computeroutput></term>
146+
<listitem>
147+
<para>
148+
Message returned if the domain is successfully created.
149+
</para>
150+
</listitem>
151+
</varlistentry>
152+
</variablelist>
153+
</para>
154+
</refsect2>
155+
</refsynopsisdiv>
156+
157+
<refsect1 id="R1-SQL-CREATEDOMAIN-1">
158+
<refsect1info>
159+
<date>2002-02-24</date>
160+
</refsect1info>
161+
<title>
162+
Description
163+
</title>
164+
165+
<para>
166+
<command>CREATE DOMAIN</command> allows the user to register a new user data
167+
domain with PostgreSQL for use in the current data base. The
168+
user who defines a domain becomes its owner.
169+
<replaceable class="parameter">domainname</replaceable> is
170+
the name of the new type and must be unique within the
171+
types and domains defined for this database.
172+
</para>
173+
174+
<para>
175+
Domains are useful for abstracting common fields between tables into
176+
a single location for maintenance. An email address column may be used
177+
in several tables, all with the same properties. Define a domain and
178+
use that rather than setting up each tables constraints individually.
179+
</para>
180+
</refsect1>
181+
182+
<refsect1>
183+
<title>Examples</title>
184+
<para>
185+
This example creates the <type>country_code</type> data type and then uses the
186+
type in a table definition:
187+
<programlisting>
188+
CREATE DOMAIN country_code char(2) NOT NULL;
189+
CREATE TABLE countrylist (id INT4, country country_code);
190+
</programlisting>
191+
</para>
192+
</refsect1>
193+
194+
<refsect1 id="SQL-CREATEDOMAIN-compatibility">
195+
<title>Compatibility</title>
196+
197+
<para>
198+
This <command>CREATE DOMAIN</command> command is a
199+
<productname>PostgreSQL</productname> extension. CHECK and FOREIGN KEY
200+
constraints are currently unsupported.
201+
</para>
202+
</refsect1>
203+
204+
<refsect1 id="SQL-CREATEDOMAIN-see-also">
205+
<title>See Also</title>
206+
207+
<simplelist type="inline">
208+
<member><xref linkend="sql-dropdomain"></member>
209+
<member><citetitle>PostgreSQL Programmer's Guide</citetitle></member>
210+
</simplelist>
211+
</refsect1>
212+
213+
</refentry>
214+
215+
216+
<!-- Keep this comment at the end of the file
217+
Local variables:
218+
mode: sgml
219+
sgml-omittag:nil
220+
sgml-shorttag:t
221+
sgml-minimize-attributes:nil
222+
sgml-always-quote-attributes:t
223+
sgml-indent-step:1
224+
sgml-indent-data:t
225+
sgml-parent-document:nil
226+
sgml-default-dtd-file:"../reference.ced"
227+
sgml-exposed-tags:nil
228+
sgml-local-catalogs:"/usr/lib/sgml/catalog"
229+
sgml-local-ecat-files:nil
230+
End:
231+
-->

0 commit comments

Comments
 (0)