Re: PG10 transition tables, wCTEs and multiple operations on the same table

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>, Kevin Grittner <kgrittn(at)gmail(dot)com>, Craig Ringer <craig(at)2ndquadrant(dot)com>, Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Subject: Re: PG10 transition tables, wCTEs and multiple operations on the same table
Date: 2017-06-10 13:13:32
Message-ID: 20170610131332.tfhwrtnrifthy6pc@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Robert Haas wrote:

> Not this patch's problem directly, but while scrutinizing this it
> crossed my mind that we would need to prohibit constraint triggers
> with transition tables. It turns out that we do, in the parser:
>
> create constraint trigger table2_trig
> after insert on table2 referencing new table as new_table
> for each statement execute procedure dump_insert();
> ERROR: syntax error at or near "referencing"
>
> Possibly it would be better to allow the syntax and error out in
> CreateTrigger(), so that we can give a better error message. It's
> certainly not obvious from the syntax summary produced by \h CREATE
> TRIGGER why this doesn't work.

Yeah, I agree. This doesn't look like actual protection, but just a
"happy accident", and the syntax error message is not helpful either.
We could keep it very simple by just throwing the error right there in
gram.y's production, adding TriggerReferencing in the right place in the
CREATE CONSTRAINT TRIGGER production -- at this stage there doesn't seem
to be a need to expand this any further.

> This might be more future-proof, too,
> if somebody someday adds support for REFERENCING { OLD | NEW } ROW to
> constraint triggers and fails to realize that there's not a check
> anywhere outside the parser for the table case.

I suppose in the future it would make sense to allow for-each-statement
constraint triggers with transition tables. It'd probably a useful way
to optimize FK checks for bulk operations.

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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2017-06-10 14:42:25 Re: logical replication: \dRp+ and "for all tables"
Previous Message Ashutosh Sharma 2017-06-10 09:55:31 Getting server crash on Windows when using ICU collation