PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> If you run this command multiple times:
> ALTER TABLE myschema.mytable ADD IF NOT EXISTS mycolumn uuid REFERENCES
> myschema.mytable2(userid);
> It adds the column once, but adds a duplicate FOREIGN KEY each time.
Yeah, this is a well known problem :-(. The IF NOT EXISTS conditionalizes
addition of the column, but not the quasi-independent addition of the
foreign key constraint. There's work afoot to make this behave more
intuitively, but it won't land before v13 at the earliest.
regards, tom lane