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: Fix psql \d's query for identifying parent triggers.
Date: Tue, 18 Jan 2022 02:19:23 +0000
Message-ID: <E1n9e5j-0007PD-VM@gemulon.postgresql.org> (raw)

Fix psql \d's query for identifying parent triggers.

The original coding (from c33869cc3) failed with "more than one row
returned by a subquery used as an expression" if there were unrelated
triggers of the same tgname on parent partitioned tables.  (That's
possible because statement-level triggers don't get inherited.)  Fix
by applying LIMIT 1 after sorting the candidates by inheritance level.

Also, wrap the subquery in a CASE so that we don't have to execute it at
all when the trigger is visibly non-inherited.  Aside from saving some
cycles, this avoids the need for a confusing and undocumented NULLIF().

While here, tweak the format of the emitted query to look a bit
nicer for "psql -E", and add some explanation of this subquery,
because it badly needs it.

Report and patch by Justin Pryzby (with some editing by me).
Back-patch to v13 where the faulty code came in.

Discussion: https://postgr.es/m/20211217154356.GJ17618@telsasoft.com

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/90e0f9fd8cae7cfb09c11534f690edde6d6ee06c

Modified Files
--------------
src/bin/psql/describe.c                | 45 +++++++++++++++++++++++++---------
src/test/regress/expected/triggers.out | 14 +++++++++++
src/test/regress/sql/triggers.sql      |  5 ++++
3 files changed, 53 insertions(+), 11 deletions(-)



view thread (3+ messages)

Message-ID: <E1n9e5j-0007PD-VM@gemulon.postgresql.org>
Permalink:  ../E1n9e5j-0007PD-VM@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1n9e5j-0007PD-VM@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: Fix psql \d's query for identifying parent triggers.
  In-Reply-To: <E1n9e5j-0007PD-VM@gemulon.postgresql.org>
  References: <E1n9e5j-0007PD-VM@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