Revision 14235
Added by Aaron Marcuse-Kubitza over 10 years ago
trunk/schemas/util.sql | ||
---|---|---|
868 | 868 |
CREATE FUNCTION canon_sql(expr text, table_ regtype DEFAULT NULL::regtype) RETURNS text |
869 | 869 |
LANGUAGE sql STABLE |
870 | 870 |
AS $_$ |
871 |
-- **IMPORTANT**: need to include the enclosing () because the DB includes them
|
|
872 |
SELECT (regexp_matches(line, |
|
873 |
'^ Filter: \((.*) IS DISTINCT FROM result_type_null\)$'))[1] |
|
871 |
-- **IMPORTANT**: need to remove the enclosing () to be consistent everywhere
|
|
872 |
SELECT util.trim_parens((regexp_matches(line,
|
|
873 |
'^ Filter: \((.*) IS DISTINCT FROM result_type_null\)$'))[1])
|
|
874 | 874 |
FROM util.explain($$ |
875 | 875 |
-- declare types (use WITH to avoid `types.` prefix) |
876 | 876 |
WITH types AS |
... | ... | |
1084 | 1084 |
CREATE FUNCTION check_constraint_expr_enable(expr text) RETURNS text |
1085 | 1085 |
LANGUAGE sql IMMUTABLE |
1086 | 1086 |
AS $_$ |
1087 |
-- **IMPORTANT**: need to remove the enclosing () to be consistent everywhere |
|
1087 | 1088 |
SELECT util.trim_parens(util.remove_prefix($$true OR $$, util.trim_parens(expr), |
1088 | 1089 |
require:= false)) |
1089 | 1090 |
$_$; |
... | ... | |
1869 | 1870 |
CREATE FUNCTION derived_col_expr_from_check_constraint(check_constraint_def check_constraint_def) RETURNS text |
1870 | 1871 |
LANGUAGE sql IMMUTABLE |
1871 | 1872 |
AS $_$ |
1873 |
-- **IMPORTANT**: need to remove the enclosing () to be consistent everywhere |
|
1872 | 1874 |
SELECT util.trim_parens(util.extract_str( |
1873 | 1875 |
quote_ident((check_constraint_def).constraint_.name)||$$ IS DISTINCT FROM $$,'', |
1874 | 1876 |
util.trim_parens(util.remove_prefix($$NOT $$, util.trim_parens( |
... | ... | |
6084 | 6086 |
ROW(ROW(s.table_, (s.name)::text), s.def)::check_constraint_def AS constraint_ |
6085 | 6087 |
FROM ( SELECT (pg_constraint.conrelid)::regclass AS table_, |
6086 | 6088 |
pg_constraint.conname AS name, |
6087 |
pg_constraint.consrc AS def
|
|
6089 |
trim_parens(pg_constraint.consrc) AS def
|
|
6088 | 6090 |
FROM pg_constraint |
6089 | 6091 |
WHERE (pg_constraint.contype = 'c'::"char")) s; |
6090 | 6092 |
|
... | ... | |
6094 | 6096 |
-- |
6095 | 6097 |
|
6096 | 6098 |
COMMENT ON VIEW check_constraint IS ' |
6097 |
consrc: *don''t* use `pg_get_expr(conbin, conrelid, /*pretty-print:*/true)`, |
|
6098 |
because this format does not match util.canon_sql() |
|
6099 |
consrc: |
|
6100 |
**IMPORTANT**: need to remove the enclosing () to be consistent everywhere. |
|
6101 |
*don''t* use `pg_get_expr(conbin, conrelid, /*pretty-print:*/true)`, |
|
6102 |
because this format does not match util.canon_sql(). |
|
6099 | 6103 |
'; |
6100 | 6104 |
|
6101 | 6105 |
|
Also available in: Unified diff
bugfix: schemas/util.sql: CHECK constraint exprs: need to remove the enclosing () to be consistent everywhere