I wrote:
> I don't think this is pg_dump's fault: there is no such constraint
> when the ALTER TABLE starts. Something inside the ALTER TABLE
> recursion seems to be messing up if there is already another
> similar FK constraint.
Oh, I see what's happening. We create both the specified constraint
and an inherited child constraint on the named partitioned table.
If tt_a_fkey is added first, the name chosen for its child is
"tt_i_fkey", breaking the later attempt by the user to use that name.
Apparently there is some hack in psql to not show that child
constraint entry, because you don't see it in \d output, which
is what confused me before (and would confuse most people
hitting this).
We could fool around with the generation rule for the child
constraint's name, but fundamentally we're infringing on user
namespace here, so I think that's likely to just move the problem
cases around. Why do we need this child pg_constraint entry at all?
If we can't avoid having it, probably choosing a name like
"tt_a_fkey1" would be marginally less likely to cause trouble
... but only marginally.
In any case, it's pretty awful that we make these entries but
\d does not show them.
regards, tom lane