Revision 13637
Added by Aaron Marcuse-Kubitza over 10 years ago
trunk/schemas/util.sql | ||
---|---|---|
2879 | 2879 |
|
2880 | 2880 |
|
2881 | 2881 |
-- |
2882 |
-- Name: pg_get_viewdef(regclass); Type: FUNCTION; Schema: util; Owner: - |
|
2883 |
-- |
|
2884 |
|
|
2885 |
CREATE FUNCTION pg_get_viewdef(view_ regclass) RETURNS text |
|
2886 |
LANGUAGE sql IMMUTABLE |
|
2887 |
AS $_$ |
|
2888 |
/* unexpand expanded * expressions. any list of 5+ cols from the same table is |
|
2889 |
treated as a * expression. */ |
|
2890 |
SELECT regexp_replace(pg_catalog.pg_get_viewdef($1), |
|
2891 |
'\y((?:"[^"]+"|\w+)\.)(?:"[^"]+"|\w+)'|| --1st col, which lacks separator before |
|
2892 |
'(,[[:blank:]]* |
|
2893 |
[[:blank:]]*)\1(?:"[^"]+"|\w+)'|| -- 2nd col, which has separator before |
|
2894 |
'(?:\2\1(?:"[^"]+"|\w+)){4,}', -- later cols, w/ same table name and separator |
|
2895 |
'\1*'/*prefix w/ table*/, 'g') |
|
2896 |
$_$; |
|
2897 |
|
|
2898 |
|
|
2899 |
-- |
|
2882 | 2900 |
-- Name: populate_table(regclass, text); Type: FUNCTION; Schema: util; Owner: - |
2883 | 2901 |
-- |
2884 | 2902 |
|
Also available in: Unified diff
schemas/util.sql: added pg_get_viewdef() wrapper, which unexpands expanded * expressions