Re: BUG #18038: Aliases removed from view definitions

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: asier(dot)lostale(at)openbravo(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18038: Aliases removed from view definitions
Date: 2023-07-27 14:00:29
Message-ID: 2057266.1690466429@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> When defining a view in 16beta2, the sql representing that view removes
> aliases. In previous versions those aliases where kept; furthermore, aliases
> were added even if not defined.

This is not a bug: there is nothing incorrect about either display
of the view.

I believe the proximate cause of the change is that there's a
heuristic in the parsetree decompiler to not attach a table alias to
a Var's name when there is only one relation in the range table (and
thus, no possible ambiguity). That heuristic has been there for
decades, but it didn't fire in these specific cases because CREATE
VIEW attached some extra hidden range table entries to perform
permissions checking on the view itself. That doesn't happen anymore
(the permissions checking is handled in another way now), so presto
no redundant alias.

We could alter or remove that heuristic, but not without changing
the behavior in yet other cases, so I doubt that twiddling it
would fix your problem in general.

> In our case this is problematic as in our application we export view
> definitions to text files to later import them, we support different
> PostgreSQL versions and we would need to keep stable SQL among different
> version (export <-> import).

I'm afraid your application has been built on sand. We change
insignificant details of view/rule decompiling all the time,
and are not likely to stop. I might have more sympathy for
your request if it didn't imply putting ruleutils.c into an
impossible straitjacket for all time to come.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Jeff Davis 2023-07-27 18:21:25 search_path not recomputed when role name changes
Previous Message Ba Jinsheng 2023-07-27 08:17:58 Question about double table scans for a table