From 7fdb4305db20f64bce27e6bac0a0f9c972e4dec8 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 5 Apr 2006 22:11:58 +0000 Subject: Fix a bunch of problems with domains by making them use special input functions that apply the necessary domain constraint checks immediately. This fixes cases where domain constraints went unchecked for statement parameters, PL function local variables and results, etc. We can also eliminate existing special cases for domains in places that had gotten it right, eg COPY. Also, allow domains over domains (base of a domain is another domain type). This almost worked before, but was disallowed because the original patch hadn't gotten it quite right. --- doc/src/sgml/ref/create_domain.sgml | 45 +++++++++++++++---------------------- doc/src/sgml/ref/create_type.sgml | 3 ++- 2 files changed, 20 insertions(+), 28 deletions(-) (limited to 'doc') diff --git a/doc/src/sgml/ref/create_domain.sgml b/doc/src/sgml/ref/create_domain.sgml index 4beb0ae53b..bfed902739 100644 --- a/doc/src/sgml/ref/create_domain.sgml +++ b/doc/src/sgml/ref/create_domain.sgml @@ -1,5 +1,5 @@ @@ -35,8 +35,10 @@ where constraint is: Description - CREATE DOMAIN creates a new data domain. The - user who defines a domain becomes its owner. + CREATE DOMAIN creates a new domain. A domain is + essentially a data type with optional constraints (restrictions on + the allowed set of values). + The user who defines a domain becomes its owner. @@ -48,24 +50,13 @@ where constraint is: - Domains are useful for abstracting common fields between tables - into a single location for maintenance. For example, an email address - column may be used in several tables, all with the same properties. - Define a domain and use that rather than setting up each table's - constraints individually. + Domains are useful for abstracting common constraints on fields into + a single location for maintenance. For example, several tables might + contain email address columns, all requiring the same CHECK constraint + to verify the address syntax. + Define a domain rather than setting up each table's constraint + individually. - - - - At present, declaring a function result value as a domain - is pretty dangerous, because none of the procedural languages enforce domain constraints - on their results. You'll need to make sure that the function code itself - respects the constraints. In PL/pgSQL, one possible - workaround is to explicitly cast the result value to the domain type - when you return it. PL/pgSQL does not enforce domain - constraints for local variables within functions, either. - - @@ -156,7 +147,7 @@ where constraint is: CHECK clauses specify integrity constraints or tests which values of the domain must satisfy. Each constraint must be an expression - producing a Boolean result. It should use the name VALUE + producing a Boolean result. It should use the key word VALUE to refer to the value being tested. @@ -185,12 +176,12 @@ OR VALUE ~ '^\\d{5}-\\d{4}$' ); CREATE TABLE us_snail_addy ( - address_id SERIAL PRIMARY KEY -, street1 TEXT NOT NULL -, street2 TEXT -, street3 TEXT -, city TEXT NOT NULL -, postal us_postal_code NOT NULL + address_id SERIAL PRIMARY KEY, + street1 TEXT NOT NULL, + street2 TEXT, + street3 TEXT, + city TEXT NOT NULL, + postal us_postal_code NOT NULL ); diff --git a/doc/src/sgml/ref/create_type.sgml b/doc/src/sgml/ref/create_type.sgml index e3b8b44d8f..68ec242ae5 100644 --- a/doc/src/sgml/ref/create_type.sgml +++ b/doc/src/sgml/ref/create_type.sgml @@ -1,5 +1,5 @@ @@ -591,6 +591,7 @@ CREATE TABLE big_objs ( + -- cgit v1.2.1