Search Postgresql Archives

Re: Implementing standard SQL's DOMAIN constraint

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wednesday, January 2, 2019, Rich Shepard <rshepard@xxxxxxxxxxxxxxx> 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.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux