Create a check constraint that is based on the return value of a user-defined function
create function is_valid(p_to_check integer) returns boolean as $$ select p_to_check = 42 $$ language sql; create table answers ( question_id integer not null, answer_value integer not null check (is_valid (answer_value)) );