Restrictions When Using the Single-Column Constraint Format
When you use the single-column constraint format to define a check
constraint, the check constraint cannot depend on values in other
columns of the table. The following example creates the my_accounts table that
has two columns with check constraints, each in the single-column
constraint format:
CREATE TABLE my_accounts (
chk_id SERIAL PRIMARY KEY,
acct1 MONEY CHECK (acct1 BETWEEN 0 AND 99999),
acct2 MONEY CHECK (acct2 BETWEEN 0 AND 99999));
Both acct1 and acct2 are columns of MONEY data type
whose values must be between 0
and 99999
.
If, however, you want to test that acct1 has a larger balance
than acct2, you cannot use the single-column constraint format.
To create a constraint that checks values in more than one column,
you must use the Multiple-Column Constraint Format.