Revision 14236
Added by Aaron Marcuse-Kubitza over 10 years ago
trunk/schemas/util.sql | ||
---|---|---|
1091 | 1091 |
|
1092 | 1092 |
|
1093 | 1093 |
-- |
1094 |
-- Name: check_constraint_replace(check_constraint_def); Type: FUNCTION; Schema: util; Owner: - |
|
1094 |
-- Name: check_constraint_replace(check_constraint_def, boolean); Type: FUNCTION; Schema: util; Owner: -
|
|
1095 | 1095 |
-- |
1096 | 1096 |
|
1097 |
CREATE FUNCTION check_constraint_replace(def check_constraint_def) RETURNS void |
|
1097 |
CREATE FUNCTION check_constraint_replace(def check_constraint_def, canon boolean DEFAULT true) RETURNS void
|
|
1098 | 1098 |
LANGUAGE sql |
1099 | 1099 |
AS $_$ |
1100 | 1100 |
-- **IMPORTANT**: need to canon so it can be compared with the expr in the DB |
... | ... | |
1109 | 1109 |
||$$ CHECK ($$||expr||$$)$$) |
1110 | 1110 |
) s) |
1111 | 1111 |
END |
1112 |
FROM (SELECT util.canon_sql(def.expr, (def).constraint_.table_) AS expr) s |
|
1112 |
FROM (SELECT |
|
1113 |
CASE WHEN canon THEN util.canon_sql(def.expr, (def).constraint_.table_) |
|
1114 |
ELSE def.expr END AS expr |
|
1115 |
) s |
|
1113 | 1116 |
$_$; |
1114 | 1117 |
|
1115 | 1118 |
|
1116 | 1119 |
-- |
1117 |
-- Name: FUNCTION check_constraint_replace(def check_constraint_def); Type: COMMENT; Schema: util; Owner: - |
|
1120 |
-- Name: FUNCTION check_constraint_replace(def check_constraint_def, canon boolean); Type: COMMENT; Schema: util; Owner: -
|
|
1118 | 1121 |
-- |
1119 | 1122 |
|
1120 |
COMMENT ON FUNCTION check_constraint_replace(def check_constraint_def) IS ' |
|
1123 |
COMMENT ON FUNCTION check_constraint_replace(def check_constraint_def, canon boolean) IS '
|
|
1121 | 1124 |
idempotent, and avoids re-running constraint on all rows if expr hasn''t changed |
1122 | 1125 |
'; |
1123 | 1126 |
|
Also available in: Unified diff
schemas/util.sql: check_constraint_replace(): support not canon-ing def.expr