Trigger does not work after partitioning

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Trigger does not work after partitioning

Raschkowski, Michael

Hello,

 

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.

 

Is it a bug or I have not taken something into account?

 

Thanks in advance!  

 

Viele Grüße / Kind regards,

Dr. Michael Raschkowski
Software Architect

Auconet GmbH - ein Unternehmen der Beta Systems Gruppe
An den Treptowers 1, 12435 Berlin
Phone: +49 30 254 690-356
Fax: +49 30 254 690-199

Email: [hidden email]
www.auconet-it.com

Mandatory Information for business emails according to German trade laws / Pflichtangaben für geschäftliche E-mails gemäß Handelsgesetzbuch:

Auconet GmbH - ein Unternehmen der Beta Systems Gruppe
An den Treptowers 1
12435 Berlin
Germany
Phone: +49-(0)30-254 690-0
Fax: +49-(0))30-254 690-199
[hidden email]
www.auconet-it.com

Management / Geschäftsführer: Hartmut Bolten, Sebastian Zang
Legal form / Rechtsform: GmbH | Registered office / Sitz: Berlin
Commercial register / Handelsregister: Amtsgericht Charlottenburg HRB 141 887 B
VAT-ID / Ust-ID-Nr.: DE316422231 | Tax No. / St.-Nr.: 30/036/75431
Bank / Bankverbindung: Commerzbank AG, BIC: COBADEFF, IBAN: DE25 1004 0000 0230 9391 00

 

 


error_part_trigger.sql (971 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Trigger does not work after partitioning

Alvaro Herrera-9
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