• Tom Lane's avatar
    Fix ALTER TABLE's scheduling rules for AT_AddConstraint subcommands. · 5b02d68e
    Tom Lane authored
    Commit 1281a5c9 rearranged the logic in this area rather drastically,
    and it broke the case of adding a foreign key constraint in the same
    ALTER that adds the pkey or unique constraint it depends on.  While
    self-referential fkeys are surely a pretty niche case, this used to
    work so we shouldn't break it.
    
    To fix, reorganize the scheduling rules in ATParseTransformCmd so
    that a transformed AT_AddConstraint subcommand will be delayed into
    a later pass in all cases, not only when it's been spit out as a
    side-effect of parsing some other command type.
    
    Also tweak the logic so that we won't run ATParseTransformCmd twice
    while doing this.  It seems to work even without that, but it's
    surely wasting cycles to do so.
    
    Per bug #16589 from Jeremy Evans.  Back-patch to v13 where the new
    code was introduced.
    
    Discussion: https://postgr.es/m/16589-31c8d981ca503896@postgresql.org
    5b02d68e
alter_table.out 185 KB