Re: Implementing standard SQL's DOMAIN constraint - Mailing list pgsql-general

From David G. Johnston
Subject Re: Implementing standard SQL's DOMAIN constraint
Date
Msg-id CAKFQuwbdtPmDR52TBX1EENEbYV2w02GzB1K5z_1O-r2ukfo4Kg@mail.gmail.com
Whole thread Raw
In response to Implementing standard SQL's DOMAIN constraint  (Rich Shepard <rshepard@appl-ecosys.com>)
Responses Re: Implementing standard SQL's DOMAIN constraint
List pgsql-general
On Wednesday, January 2, 2019, Rich Shepard <rshepard@appl-ecosys.com> wrote:

CREATE DOMAIN state_code AS char(2)
DEFAULT '??'
CONSTRAINT valid_state_code
CHECK (value IN ('AL', 'AK', 'AZ', ...));

This applies to all tables each having a column named state_code.

There is no magic name logic involved.  A domain is just a type with inherent constraints that are user definable.  You make use of it like any other type.

Create table tbl (
column_name state_code not null

Values stored in column_name are now of type state_code and constrained to be one of the check constraint values.

David J.

pgsql-general by date:

Previous
From: Rich Shepard
Date:
Subject: Implementing standard SQL's DOMAIN constraint
Next
From: Rich Shepard
Date:
Subject: Re: Implementing standard SQL's DOMAIN constraint