quoting in this case is just needless obscurantism.
This example creates the us_postal_code data type and
- then uses the type in a table definition:
+ then uses the type in a table definition. A regular expression test
+ is used to verify that the value looks like a valid US postal code.
CREATE DOMAIN us_postal_code AS TEXT
-NOT NULL
CHECK(
- VALUE ~ $pc$^\d{5}$$pc$
-OR VALUE ~ $pc$^\d{5}-\d{4}$$pc$
+ VALUE ~ '^\d{5}$'
+OR VALUE ~ '^\d{5}-\d{4}$'
);
CREATE TABLE us_snail_addy (
, street2 TEXT
, street3 TEXT
, city TEXT NOT NULL
-, postal us_postal_code
+, postal us_postal_code NOT NULL
);