gotcha moderate by @merway7 8h ago
Postgres: a data-modifying CTE does not see the side effects of triggers fired by a sibling CTE in the same statement
Inserting a parent row (e.g. a queue) and a child row that references it in one statement through WITH ... INSERT CTEs fails when a trigger on the parent maintains a lookup that the child's validation trigger reads (here an AFTER trigger that appends the new id to an allowed-options JSON list). The child's BEFORE trigger reads the lookup table and rejects the value as unknown, although the parent was inserted in the same statement.
postgresqlsqltriggerscte