|
1 | 1 | <!--
|
2 |
| -$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.17 2003/11/29 19:51:38 pgsql Exp $ |
| 2 | +$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.18 2004/08/08 01:49:30 momjian Exp $ |
3 | 3 | PostgreSQL documentation
|
4 | 4 | -->
|
5 | 5 |
|
@@ -160,11 +160,25 @@ where <replaceable class="PARAMETER">constraint</replaceable> is:
|
160 | 160 | <title>Examples</title>
|
161 | 161 |
|
162 | 162 | <para>
|
163 |
| - This example creates the <type>country_code</type> data type and then uses the |
164 |
| - type in a table definition: |
| 163 | + This example creates the <type>us_postal_code</type> data type and |
| 164 | + then uses the type in a table definition: |
| 165 | + |
165 | 166 | <programlisting>
|
166 |
| -CREATE DOMAIN country_code char(2) NOT NULL; |
167 |
| -CREATE TABLE countrylist (id integer, country country_code); |
| 167 | +CREATE DOMAIN us_postal_code AS TEXT |
| 168 | +NOT NULL |
| 169 | +CHECK( |
| 170 | + VALUE ~ $pc$^\d{5}$$pc$ |
| 171 | +OR VALUE ~ $pc$^\d{5}-\d{4}$$pc$ |
| 172 | +); |
| 173 | + |
| 174 | +CREATE TABLE us_snail_addy ( |
| 175 | + address_id SERIAL NOT NULL PRIMARY KEY |
| 176 | +, street1 TEXT NOT NULL |
| 177 | +, street2 TEXT |
| 178 | +, street3 TEXT |
| 179 | +, city TEXT NOT NULL |
| 180 | +, postal us_postal_code |
| 181 | +); |
168 | 182 | </programlisting>
|
169 | 183 | </para>
|
170 | 184 | </refsect1>
|
|