Revision 14230
Added by Aaron Marcuse-Kubitza over 10 years ago
trunk/schemas/util.sql | ||
---|---|---|
1094 | 1094 |
CREATE FUNCTION check_constraint_replace(def check_constraint_def) RETURNS void |
1095 | 1095 |
LANGUAGE sql |
1096 | 1096 |
AS $_$ |
1097 |
-- **IMPORTANT**: need to canon so it can be compared with the expr in the DB |
|
1097 | 1098 |
SELECT CASE |
1098 |
WHEN def.expr IS DISTINCT FROM util.check_constraint_expr(def.constraint_) THEN
|
|
1099 |
WHEN expr IS DISTINCT FROM util.check_constraint_expr(def.constraint_) THEN |
|
1099 | 1100 |
-- only re-run constraint on all rows if expr has changed |
1100 | 1101 |
(SELECT NULL::void FROM (SELECT |
1101 | 1102 |
util.check_constraint_drop(def.constraint_) |
1102 | 1103 |
, |
1103 | 1104 |
util.eval($$ALTER TABLE $$||(def).constraint_.table_ |
1104 | 1105 |
||$$ ADD CONSTRAINT $$||quote_ident((def).constraint_.name) |
1105 |
||$$ CHECK ($$||def.expr||$$)$$)
|
|
1106 |
||$$ CHECK ($$||expr||$$)$$) |
|
1106 | 1107 |
) s) |
1107 | 1108 |
END |
1109 |
FROM (SELECT util.canon_sql(def.expr, (def).constraint_.table_) AS expr) s |
|
1108 | 1110 |
$_$; |
1109 | 1111 |
|
1110 | 1112 |
|
Also available in: Unified diff
bugfix: schemas/util.sql: check_constraint_replace(): need to canon the expr, using new util.canon_sql(), so it can be compared with the expr in the DB