Like the post at [0] suggests, HSQL CHECK constraints can not be used together with CASE WHEN statements.
If you try to insert/update, you will receive a (very informative) “S1000 General error java.lang.ClassCastException”, followed by the whole SQL statement. (here I have, HSQL 1.8.0.9).
If you have something like:
ALTER TABLE personnel ADD CONSTRAINT salary_types_constraint
CHECK (
CASE
WHEN pos = 0 AND (salary < 1000 OR salary > 5000)
THEN FALSE -- personal
WHEN pos = 1 AND (salary < 10000 OR salary > 20000)
THEN FALSE -- manager
ELSE TRUE
END
);
It will not work. It will give you a “S1000 General error java.lang.ClassCastException” error message.
Replace with:
ALTER TABLE personnel ADD CONSTRAINT salary_types_constraint
CHECK (
(pos = 0 AND (salary > 1000 OR salary < 5000))
OR
(pos = 1 AND (salary < 10000 OR salary > 20000))
);
This entry was posted on Wednesday, March 12th, 2008 and is filed under Happy Hacking. You can follow any responses to this entry through RSS 2.0.
You can leave a response, or trackback from your own site.
HSQL CHECK constraints with CASE statement
Like the post at [0] suggests, HSQL CHECK constraints can not be used together with CASE WHEN statements.
If you try to insert/update, you will receive a (very informative) “S1000 General error java.lang.ClassCastException”, followed by the whole SQL statement. (here I have, HSQL 1.8.0.9).
If you have something like:
It will not work. It will give you a “S1000 General error java.lang.ClassCastException” error message.
Replace with:
comment
This entry was posted on Wednesday, March 12th, 2008 and is filed under Happy Hacking. You can follow any responses to this entry through RSS 2.0. You can leave a response, or trackback from your own site.