pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Show 'AS "?column?"' explicitly when it's important.
Date: Sat, 21 May 2022 18:46:14 +0000
Message-ID: <E1nsU7C-000Tm1-0U@gemulon.postgresql.org> (raw)

Show 'AS "?column?"' explicitly when it's important.

ruleutils.c was coded to suppress the AS label for a SELECT output
expression if the column name is "?column?", which is the parser's
fallback if it can't think of something better.  This is fine, and
avoids ugly clutter, so long as (1) nothing further up in the parse
tree relies on that column name or (2) the same fallback would be
assigned when the rule or view definition is reloaded.  Unfortunately
(2) is far from certain, both because ruleutils.c might print the
expression in a different form from how it was originally written
and because FigureColname's rules might change in future releases.
So we shouldn't rely on that.

Detecting exactly whether there is any outer-level use of a SELECT
column name would be rather expensive.  This patch takes the simpler
approach of just passing down a flag indicating whether there *could*
be any outer use; for example, the output column names of a SubLink
are not referenceable, and we also do not care about the names exposed
by the right-hand side of a setop.  This is sufficient to suppress
unwanted clutter in all but one case in the regression tests.  That
seems like reasonable evidence that it won't be too much in users'
faces, while still fixing the cases we need to fix.

Per bug #17486 from Nicolas Lutic.  This issue is ancient, so
back-patch to all supported branches.

Discussion: https://postgr.es/m/17486-1ad6fd786728b8af@postgresql.org

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/fefd5463173a6ca598ae206b13a505297d9efecb

Modified Files
--------------
src/backend/utils/adt/ruleutils.c     | 100 ++++++++++++++++++++++------------
src/test/regress/expected/matview.out |   4 +-
2 files changed, 66 insertions(+), 38 deletions(-)



view thread (6+ messages)

Message-ID: <E1nsU7C-000Tm1-0U@gemulon.postgresql.org>
Permalink:  ../E1nsU7C-000Tm1-0U@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1nsU7C-000Tm1-0U@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Show 'AS "?column?"' explicitly when it's important.
  In-Reply-To: <E1nsU7C-000Tm1-0U@gemulon.postgresql.org>
  References: <E1nsU7C-000Tm1-0U@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox