Revision 14226
Added by Aaron Marcuse-Kubitza over 10 years ago
util.sql | ||
---|---|---|
851 | 851 |
|
852 | 852 |
|
853 | 853 |
-- |
854 |
-- Name: canon_sql(text, regtype); Type: FUNCTION; Schema: util; Owner: - |
|
855 |
-- |
|
856 |
|
|
857 |
CREATE FUNCTION canon_sql(expr text, table_ regtype DEFAULT NULL::regtype) RETURNS text |
|
858 |
LANGUAGE sql STABLE |
|
859 |
AS $_$ |
|
860 |
SELECT util.trim_parens((regexp_matches(line, |
|
861 |
'^ Filter: \((.*) IS DISTINCT FROM result_type_null\)$'))[1]) |
|
862 |
FROM util.explain($$ |
|
863 |
-- declare types (use WITH to avoid `types.` prefix) |
|
864 |
WITH types AS |
|
865 |
( |
|
866 |
SELECT |
|
867 |
NULL::$$||util.typeof(expr, table_)||$$ AS result_type_null |
|
868 |
, /*col types:*/(NULL::$$||table_||$$).* |
|
869 |
) |
|
870 |
SELECT * FROM types WHERE ($$||expr||$$) IS DISTINCT FROM result_type_null |
|
871 |
/* can't just use IS NOT NULL, or even `= result_type_null`, because these |
|
872 |
will simplify NULL exprs too far */ |
|
873 |
$$) line |
|
874 |
LIMIT 1 |
|
875 |
$_$; |
|
876 |
|
|
877 |
|
|
878 |
-- |
|
854 | 879 |
-- Name: cast(text, anyelement); Type: FUNCTION; Schema: util; Owner: - |
855 | 880 |
-- |
856 | 881 |
|
Also available in: Unified diff
schemas/util.sql: added canon_sql(expr text)