Revision 14237
Added by Aaron Marcuse-Kubitza over 10 years ago
trunk/schemas/util.sql | ||
---|---|---|
946 | 946 |
|
947 | 947 |
|
948 | 948 |
-- |
949 |
-- Name: check_constraint_canon_sql(check_constraint_def); Type: FUNCTION; Schema: util; Owner: - |
|
950 |
-- |
|
951 |
|
|
952 |
CREATE FUNCTION check_constraint_canon_sql(def check_constraint_def) RETURNS text |
|
953 |
LANGUAGE plpgsql STRICT |
|
954 |
AS $$ |
|
955 |
-- must be declared STRICT to handle NULL properly |
|
956 |
/* **IMPORTANT**: must be declared VOLATILE to be able to see concurrent |
|
957 |
modifications to system catalogs */ |
|
958 |
DECLARE |
|
959 |
result text; |
|
960 |
table_ regclass = (def).constraint_.table_; |
|
961 |
temp_table text = util.qual_name('pg_temp', util.name(table_)); |
|
962 |
temp_constraint_def util.check_constraint_def; |
|
963 |
BEGIN |
|
964 |
BEGIN |
|
965 |
-- use empty temp table so don't try to run constraint on all rows |
|
966 |
PERFORM util.copy_struct(table_, temp_table); |
|
967 |
-- now that table's regclass exists |
|
968 |
temp_constraint_def = ((temp_table, (def).constraint_.name), def.expr); |
|
969 |
|
|
970 |
PERFORM util.check_constraint_replace(temp_constraint_def, |
|
971 |
canon := false/*avoid infinite recursion*/); |
|
972 |
result = util.check_constraint_expr(temp_constraint_def.constraint_); |
|
973 |
|
|
974 |
-- delete temp tables |
|
975 |
PERFORM util.raise('ROLBK', 'sandbox block finished and rolled back'); |
|
976 |
EXCEPTION |
|
977 |
WHEN SQLSTATE 'ROLBK' THEN NULL; |
|
978 |
END; |
|
979 |
|
|
980 |
RETURN result; |
|
981 |
END; |
|
982 |
$$; |
|
983 |
|
|
984 |
|
|
985 |
-- |
|
986 |
-- Name: FUNCTION check_constraint_canon_sql(def check_constraint_def); Type: COMMENT; Schema: util; Owner: - |
|
987 |
-- |
|
988 |
|
|
989 |
COMMENT ON FUNCTION check_constraint_canon_sql(def check_constraint_def) IS ' |
|
990 |
**WARNING**: this must be used instead of plain util.canon_sql() because unlike |
|
991 |
queries, CHECK constraints are not simplified, just standardized |
|
992 |
'; |
|
993 |
|
|
994 |
|
|
995 |
-- |
|
949 | 996 |
-- Name: check_constraint_def(table_item); Type: FUNCTION; Schema: util; Owner: - |
950 | 997 |
-- |
951 | 998 |
|
Also available in: Unified diff
schemas/util.sql: added check_constraint_canon_sql(). this must be used instead of plain util.canon_sql() because unlike queries, CHECK constraints are not simplified, just standardized.