2

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?

1 Answer 1

2

Place the composite value in parentheses:

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

The issue is explained in Accessing Composite Types.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh wow. So this was only a syntax problem after all? And there I was, assuming it was a semantic problem. Could you maybe add a documentation reference stating that VALUE should be put in parentheses?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.