Subject | Context variables in CHECK constraints |
---|---|
Author | Marco Bommeljé |
Post date | 2003-11-28T12:13:59Z |
Hello everyone (especially Helen Borrie),
In a recent discussion on Transaction Isolation levels, Helen wrote:
-1-
What is so bad about using subqueries in CHECK constraints (provided
that they only SELECT on FK referenced tables)?
In my opinion, subqueries in CHECK constraints adds expressive power to
the constraints. Not using this possibility would limit the use of CHECK
constraints to the simplest checking of row values like in Oracle.
-2-
What is wrong with using the NEW and OLD context variables in CHECK
constraints? I realize that it isn't documented, but it seems to work.
Some existing database implementations rely on these features, so I like
to know in what kind of mess I am in.
Thanks,
Marco
In a recent discussion on Transaction Isolation levels, Helen wrote:
> You can *write* a check constraint that reads a value in anotherand later in the same thread:
> table but it's a practice I strongly advise against.
> .. a subquery on another table? (the one I recommended not to do)?I have two questions about this:
>
> Something like
> Alter table add constraint
> check(new.some_flag in (select flags.flag from flags))
-1-
What is so bad about using subqueries in CHECK constraints (provided
that they only SELECT on FK referenced tables)?
In my opinion, subqueries in CHECK constraints adds expressive power to
the constraints. Not using this possibility would limit the use of CHECK
constraints to the simplest checking of row values like in Oracle.
-2-
What is wrong with using the NEW and OLD context variables in CHECK
constraints? I realize that it isn't documented, but it seems to work.
Some existing database implementations rely on these features, so I like
to know in what kind of mess I am in.
Thanks,
Marco