On Mon, 27 Jun 2022 at 16:12, Julien Rouhaud <rjuju...@gmail.com> wrote: > > It doesn't play that well if you have something called subquery though: > > [example that changes a user-provided alias] > > While the output is a valid query, it's not nice that it's replacing a > user provided alias with another one (or force an alias if you have a > relation called subquery).
It's already the case that user-provided aliases can get replaced by new ones in the query-deparsing code, e.g.: CREATE OR REPLACE VIEW test_view AS SELECT x.a, y.b FROM foo AS x, (SELECT b FROM foo AS x) AS y; \sv test_view CREATE OR REPLACE VIEW public.test_view AS SELECT x.a, y.b FROM foo x, ( SELECT x_1.b FROM foo x_1) y and similarly it may invent technically unnecessary aliases where there were none before. The query-deparsing code has never been alias-preserving, unless you take care to give everything a globally unique alias. Regards, Dean