|
| 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