Add public ruleutils.c entry point to deparse a Query.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 28 Mar 2022 15:19:29 +0000 (11:19 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 28 Mar 2022 15:19:37 +0000 (11:19 -0400)
commitd22646922d66012705e0e2948cfb5b4a07092a29
treea164d1fb3006ff27218171b94e1343a67ebf1574
parent386ca0abf4107721a363f1c152cd026041b609ea
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
src/backend/utils/adt/ruleutils.c
src/include/utils/ruleutils.h