Re: Implementing standard SQL's DOMAIN constraint

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Implementing standard SQL's DOMAIN constraint
Date: 2019-01-02 17:34:32
Message-ID: CAKFQuwbdtPmDR52TBX1EENEbYV2w02GzB1K5z_1O-r2ukfo4Kg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wednesday, January 2, 2019, Rich Shepard <rshepard(at)appl-ecosys(dot)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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rich Shepard 2019-01-02 17:47:42 Re: Implementing standard SQL's DOMAIN constraint
Previous Message Rich Shepard 2019-01-02 17:12:47 Implementing standard SQL's DOMAIN constraint