Revision 13645
Added by Aaron Marcuse-Kubitza over 10 years ago
util.sql | ||
---|---|---|
4449 | 4449 |
CREATE FUNCTION view_def_to_orig(view_def text) RETURNS text |
4450 | 4450 |
LANGUAGE sql IMMUTABLE |
4451 | 4451 |
AS $_$ |
4452 |
SELECT |
|
4453 |
regexp_replace( |
|
4454 |
regexp_replace( |
|
4455 |
$1 |
|
4456 |
, |
|
4452 | 4457 |
/* unexpand expanded * expressions. any list of 6+ cols from the same table is |
4453 | 4458 |
treated as a * expression. */ |
4454 |
SELECT regexp_replace($1, |
|
4455 | 4459 |
'((?:"[^"\s]+"|\w+)\.)(?:"[^"\s]+"|\w+)'|| |
4456 | 4460 |
/* 1st col, which lacks separator before. |
4457 | 4461 |
*note*: can't prepend \y because it considers only \w chars, not " */ |
4458 | 4462 |
'(,[[:blank:]]* |
4459 | 4463 |
[[:blank:]]*)\1(?:"[^"\s]+"|\w+)'|| -- 2nd col, which has separator before |
4460 | 4464 |
'(?:\2\1(?:"[^"\s]+"|\w+)){4,}', -- later cols, w/ same table name and separator |
4461 |
'\1*'/*prefix w/ table*/, 'g') |
|
4465 |
'\1*'/*prefix w/ table*/, |
|
4466 |
'g') |
|
4467 |
, |
|
4468 |
/* merge .* expressions resulting from a SELECT * of a join. any list of |
|
4469 |
multiple .* expressions is treated as a SELECT * . */ |
|
4470 |
'(?:"[^"\s]+"|\w+)\.\*'|| |
|
4471 |
/* 1st table, which lacks separator before. |
|
4472 |
*note*: can't prepend \y because it considers only \w chars, not " */ |
|
4473 |
'(,[[:blank:]]* |
|
4474 |
[[:blank:]]*)(?:"[^"\s]+"|\w+)\.\*'|| -- 2nd table, which has separator before |
|
4475 |
'(?:\1(?:"[^"\s]+"|\w+)\.\*)*', -- later tables, w/ same separator |
|
4476 |
'*', |
|
4477 |
'g') |
|
4462 | 4478 |
$_$; |
4463 | 4479 |
|
4464 | 4480 |
|
Also available in: Unified diff
fix: schemas/util.sql: view_def_to_orig(): also need to merge .* expressions resulting from a SELECT * of a join, to avoid duplicated columns