Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n08lf-0000hR-6R for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Dec 2021 21:03:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n08lc-0007mH-Ku for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Dec 2021 21:03:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n08lc-0007m8-6Y for pgsql-hackers@lists.postgresql.org; Wed, 22 Dec 2021 21:03:20 +0000 Received: from mail-il1-x12b.google.com ([2607:f8b0:4864:20::12b]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1n08lU-0004ow-52 for pgsql-hackers@postgresql.org; Wed, 22 Dec 2021 21:03:19 +0000 Received: by mail-il1-x12b.google.com with SMTP id e8so2727841ilm.13 for ; Wed, 22 Dec 2021 13:03:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=UDiaQnwe5VVXbEFuCNCGvh0QJ8DPy4BbiwGm1JDyYx0=; b=hPHreHJ5ImpODrxhAqqL96dfZlYUuYFDBDLhw8JMaaoA6Sg422euqaI8xgPpyh/9nc J07bVnSvKuoui3h0SQo6sG6IJUtL4Zi4U/JbZrsFg+GUizFvtxin67LmU6z0Wz+sRtA+ vpLvbl0M+2rzhOKPRmEEu9I9CwG2Vovi+1u96+YbtNjIA4b8FH6/gaDmhwnklkb5Hiwn 0ePs2eaO7Xg52bFuuPAg2cxLj5NVpd4f/ZHvQ/ji5KcX/1dmANm8+ubBzUXUNW6sSajI OPQhgb6n73yVo0fXlZOnoW4TabdqL9tNglcCTcnbAZEc42K8HpAz7zY6ThNmXYmLql4Q THHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=UDiaQnwe5VVXbEFuCNCGvh0QJ8DPy4BbiwGm1JDyYx0=; b=6LvtShewz4UEywFFNqr5nyRHQ7YV0iJZalSZTpb09A6vPt567jI8GWQMHvsiKiPhVJ q4KYa6Y8sia4QWkJG1s2ZC4kCY7e4ytXfStlbnA0fj9wPrZLqQ8T5Zcey2Opq6bEGazw ZW6N424qu4hSU0GeevcuUczZQBmL++DwGdILpL+i054/l61v83mCb0Xqq3Ua0+VpMfRf pAvKarMhqpUd6C101XmFdnLZk9sTTCGS3OBHRK04vc1iWl7mAsVDcC35jCHeaLmuDuxD D06WqEKCzRxrSaXeaIGbgf+ETNkInBFMkPl1ysXkfYAPDlN66+DKQSg+FRBA/SVv9vxj XwqQ== X-Gm-Message-State: AOAM531y/wZ6jarHw5h9C62IDRexgw0qj3guRWwN3kUdmKsqAmOMBfce ulbJYI8cwbZzpmRNypau0ioDVw== X-Google-Smtp-Source: ABdhPJwdkrgLAsTYNY34ckPC7PrFzD/kjaGcxC47Hbrd+3F6bcIf3R7GnkHdE3wm60Jb+UCfTydJFA== X-Received: by 2002:a92:670e:: with SMTP id b14mr2263348ilc.39.1640206990403; Wed, 22 Dec 2021 13:03:10 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id o1sm1628144ilj.41.2021.12.22.13.03.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Dec 2021 13:03:09 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 21402800BCE; Wed, 22 Dec 2021 15:03:09 -0600 (CST) Date: Wed, 22 Dec 2021 15:03:08 -0600 From: Justin Pryzby To: Alvaro Herrera Cc: Tom Lane , pgsql-hackers@postgresql.org, Amit Langote Subject: Re: \d with triggers: more than one row returned by a subquery used as an expression Message-ID: <20211222210308.GD17618@telsasoft.com> References: <20211217154356.GJ17618@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="fuRgIt480xB0EInP" Content-Disposition: inline In-Reply-To: <20211217154356.GJ17618@telsasoft.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --fuRgIt480xB0EInP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Dec 17, 2021 at 09:43:56AM -0600, Justin Pryzby wrote: > I want to mention that the 2nd problem I mentioned here is still broken. > https://www.postgresql.org/message-id/20210717010259.GU20208@telsasoft.com > > It happens if non-inheritted triggers on child and parent have the same name. This is the fix I was proposing It depends on pg_partition_ancestors() to return its partitions in order: this partition => parent => ... => root. --fuRgIt480xB0EInP Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-psql-fix-d-for-statement-triggers-with-same-name-on-.patch" From 1c7282f5c06197e178bd23c50a226a148cb66bc8 Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Fri, 16 Jul 2021 19:57:00 -0500 Subject: [PATCH 1/2] psql: fix \d for statement triggers with same name on partition and its parent This depends on pg_partition_ancestors() to return its partitions in order: this partition => parent => ... => root. 20210716193319.GS20208@telsasoft.com --- src/bin/psql/describe.c | 2 +- src/test/regress/expected/triggers.out | 13 +++++++++++++ src/test/regress/sql/triggers.sql | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 42bad9281ed..7ad10fa1a3f 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -3012,7 +3012,7 @@ describeOneTableDetails(const char *schemaname, " FROM pg_catalog.pg_trigger AS u, " " pg_catalog.pg_partition_ancestors(t.tgrelid) AS a" " WHERE u.tgname = t.tgname AND u.tgrelid = a.relid" - " AND u.tgparentid = 0) AS parent" : + " AND u.tgparentid = 0 LIMIT 1) AS parent" : "NULL AS parent"), oid); if (pset.sversion >= 110000) diff --git a/src/test/regress/expected/triggers.out b/src/test/regress/expected/triggers.out index 9d529e949f4..44c8cdf206f 100644 --- a/src/test/regress/expected/triggers.out +++ b/src/test/regress/expected/triggers.out @@ -2122,6 +2122,19 @@ Triggers: alter table trigpart attach partition trigpart3 FOR VALUES FROM (2000) to (3000); -- fail ERROR: trigger "trg1" for relation "trigpart3" already exists drop table trigpart3; +create trigger samename after delete on trigpart execute function trigger_nothing(); +create trigger samename after delete on trigpart1 execute function trigger_nothing(); +\d trigpart1 + Table "public.trigpart1" + Column | Type | Collation | Nullable | Default +--------+---------+-----------+----------+--------- + a | integer | | | + b | integer | | | +Partition of: trigpart FOR VALUES FROM (0) TO (1000) +Triggers: + samename AFTER DELETE ON trigpart1 FOR EACH STATEMENT EXECUTE FUNCTION trigger_nothing() + trg1 AFTER INSERT ON trigpart1 FOR EACH ROW EXECUTE FUNCTION trigger_nothing(), ON TABLE trigpart + drop table trigpart; drop function trigger_nothing(); -- diff --git a/src/test/regress/sql/triggers.sql b/src/test/regress/sql/triggers.sql index eaab642950b..f644a64ca7d 100644 --- a/src/test/regress/sql/triggers.sql +++ b/src/test/regress/sql/triggers.sql @@ -1428,6 +1428,10 @@ create trigger trg1 after insert on trigpart3 for each row execute procedure tri alter table trigpart attach partition trigpart3 FOR VALUES FROM (2000) to (3000); -- fail drop table trigpart3; +create trigger samename after delete on trigpart execute function trigger_nothing(); +create trigger samename after delete on trigpart1 execute function trigger_nothing(); +\d trigpart1 + drop table trigpart; drop function trigger_nothing(); -- 2.17.0 --fuRgIt480xB0EInP Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0002-psql-Add-newlines-and-spacing-in-trigger-query-for-d.patch" From 543badde5a9bc536d5072cdafd4947a46bfb3efa Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Fri, 3 Apr 2020 22:43:26 -0500 Subject: [PATCH 2/2] psql: Add newlines and spacing in trigger query for \d cosmetic change to c33869cc3 to make the output of psql -E look pretty. --- src/bin/psql/describe.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 7ad10fa1a3f..a82c945a9a2 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -3007,12 +3007,12 @@ describeOneTableDetails(const char *schemaname, "t.tgenabled, t.tgisinternal, %s\n" "FROM pg_catalog.pg_trigger t\n" "WHERE t.tgrelid = '%s' AND ", - (pset.sversion >= 130000 ? - "(SELECT (NULLIF(a.relid, t.tgrelid))::pg_catalog.regclass" - " FROM pg_catalog.pg_trigger AS u, " - " pg_catalog.pg_partition_ancestors(t.tgrelid) AS a" - " WHERE u.tgname = t.tgname AND u.tgrelid = a.relid" - " AND u.tgparentid = 0 LIMIT 1) AS parent" : + (pset.sversion >= 130000 ? "\n" + " (SELECT (NULLIF(a.relid, t.tgrelid))::pg_catalog.regclass\n" + " FROM pg_catalog.pg_trigger AS u,\n" + " pg_catalog.pg_partition_ancestors(t.tgrelid) AS a\n" + " WHERE u.tgname = t.tgname AND u.tgrelid = a.relid\n" + " AND u.tgparentid = 0 LIMIT 1) AS parent" : "NULL AS parent"), oid); if (pset.sversion >= 110000) -- 2.17.0 --fuRgIt480xB0EInP--