Add public ruleutils.c entry point to deparse a Query.
This has no in-core callers but will be wanted by extensions.
It's just a thin wrapper around get_query_def, so it adds little code.
Also, fix get_from_clause_item() to force insertion of an alias
for a SUBQUERY RTE item. This is irrelevant to existing uses because
RTE_SUBQUERY items made by the parser always have aliases already.
However, if one tried to use pg_get_querydef() to inspect a post-rewrite
Query, it could be an issue. In any case, get_from_clause_item already
contained logic to force alias insertion for VALUES items, so the lack
of the same for SUBQUERY is a pretty clear oversight.
In passing, replace duplicated code for selection of pretty-print
options with a common macro.
Julien Rouhaud, reviewed by Pavel Stehule, Gilles Darold, and myself
Discussion: https://postgr.es/m/20210627041138.zklczwmu3ms4ufnk@nol
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/d22646922d66012705e0e2948cfb5b4a07092a29
Modified Files
--------------
src/backend/utils/adt/ruleutils.c | 54 ++++++++++++++++++++++++++++++---------
src/include/utils/ruleutils.h | 1 +
2 files changed, 43 insertions(+), 12 deletions(-)