I can't seem to figure out how to get a custom domain to accept a NULL value. Notice, for shits and giggles I've tried it many different ways:
DROP SCHEMA census CASCADE;
CREATE SCHEMA census;
-- FIRST FOUR METHODS: NULL before CHECK, in CHECK, and NULL after CHECK
CREATE DOMAIN census.sex AS text NULL CHECK ( VALUE IN ('M', 'F', 'NULL') OR VALUE IS NULL ) NULL;
CREATE TABLE census.names (
name text
, freq int
, cumfreq float
, rank float
, is_last bool
, sex census.sex NULL -- fourth way
, PRIMARY KEY ( is_last, sex, name )
);
But, still no luck...
# \d census.names;
Table "census.names"
Column | Type | Modifiers
---------+------------------+-----------
name | text | not null
freq | integer |
cumfreq | double precision |
rank | double precision |
is_last | boolean | not null
sex | census.sex | not null
Indexes:
"names_pkey" PRIMARY KEY, btree (is_last, sex, name)
More amusingly, the docs say
NULL
Values of this domain are allowed to be null. This is the default.
This clause is only intended for compatibility with nonstandard SQL databases. Its use is discouraged in new applications.
Without the clause it still says NOT NULL
.
$ psql --version
psql (PostgreSQL) 9.1.1
contains support for command-line editing