Re: Trigger does not work after partitioning

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: "Raschkowski, Michael" <michael(dot)raschkowski(at)auconet-it(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org, Hartmut Bolten <hartmut(dot)bolten(at)auconet-it(dot)com>, Hannes Just <hannes(dot)just(at)auconet-it(dot)com>
Subject: Re: Trigger does not work after partitioning
Date: 2020-03-19 17:42:57
Message-ID: 20200319174257.GA5010@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 2020-Mar-19, Raschkowski, Michael wrote:

> I am using Postgres 12.1 on Windows 10.
>
> I wrote the script for the partitioning of some tables and have
> noticed that some triggers do not work after partitioning. In attached
> example, you can see that the table test1 gets a trigger that sets the
> field instancenbr to 1 after each insertion. Nevertheless, the field
> instancenbr stays to have NULL-Value.

This has never worked, regardless of partitioning. AFTER triggers
cannot usefully change the affected row; if you want to do that, you
need a BEFORE trigger. The "return NEW" line is useless in an AFTER
trigger.

BEFORE triggers are not supported with partitioned tables (except in the
future Postgres 13, where I added that feature yesterday), but you can
add the trigger to each partition and it should work correctly. Of
course, you'll need to add the trigger manually on each partition you
create or attach.

--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Robert Haas 2020-03-20 02:21:53 Re: BUG #16302: too many range table entries - when count partition table(65538 childs)
Previous Message Raschkowski, Michael 2020-03-19 16:44:59 Trigger does not work after partitioning