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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix psql \d's query for identifying parent triggers.
Date: 2022-01-18 02:19:23
Message-ID: E1n9e5j-0007PD-VM@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message John Naylor 2022-01-18 04:03:41 pgsql: Improve code clarity in epilogue of UTF-8 verification fast path
Previous Message Andres Freund 2022-01-18 01:28:08 Re: pgsql: tests: Consistently use pg_basebackup -cfast --no-sync to accele