Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to define CHECK constraint for a Postgres DOMAIN that is based on a composite type

I would like to define a Postgres domain with check constraints based on a custom composite type.

An example for a naive approach would be this:

CREATE TYPE raw_comp_foo AS (
    min_value    integer,
    max_value    integer
);
CREATE DOMAIN comp_foo AS raw_comp_foo
CHECK (VALUE.min_value < VALUE.max_value);

However, I get the error message missing FROM-clause entry for table "value".
How can I achieve the desired constraint in the example above?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Place the composite type value in parentheses:

CREATE DOMAIN comp_foo AS raw_comp_foo
CHECK ((VALUE).min_value < (VALUE).max_value);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading