On 10 Nov 2001 at 20:41 (-0500), Tom Lane wrote:
| Brent Verner <brent@rcfile.org> writes:
| > ... but we have to check both PK_RELNAME and FK_RELNAME,
| > since we don't know which side of the constraint this relname is on.
|
| But we do, because we know whether we're scanning by tgrelid or
| tgconstrrelid.
My brain is not stretching far enough to see this. Yes, we know
what we are scanning on, but that stilll doesn't tell us which
side of the FK/PK relation this relname is on.
CREATE TABLE p_rel (id int UNIQUE);
CREATE TABLE f_rel (id int REFERENCES p_rel(id) ON UPDATE CASCADE);
p_rel.id is our PK
f_rel.id is our FK
scan on tgrelid==p_rel.oid : 2 tuples.
scan on tgconstrrelid==p_rel.oid : 1 tuple.
scan on tgrelid==f_rel.oid : 1 tuple.
scan on tgconstrrelid==f_rel.oid : 2 tuples.
AFAICS, given a relname, the only way we can know if it is the PK or
FK is the number of tuples a known scan returns. What am I missing
here?
| Another thing in the back of my mind is that I think ALTER RENAME TABLE
| has the same problem as ALTER RENAME COLUMN: the relnames in RI triggers
| need to be fixed, and aren't getting fixed. It seems to me that this
| scan subroutine could be the workhorse for solving both problems, if
| it's defined to do string substitution in a particular field of the
| RI trigger args. The scan subr should be something like
|
| update_ri_trigger_args (Oid relid,
| bool scan_by_constrrelid,
| int tgargs_item_num,
| const char *oldname,
| const char *newname)
I wasn't aware of the related ALTER RENAME TABLE problem. This is
certainly an appropriate solution. I'll work to do what you suggest.
| BTW, you probably need a CommandCounterIncrement between the two scans
| in each case. Otherwise the second scan doesn't see the tuples already
| updated by the first, which is deadly if there are any self-referential
| triggers.
cool. Thanks for alerting me of this danger -- I had no idea.
thanks.
b
--
"Develop your talent, man, and leave the world something. Records are
really gifts from people. To think that an artist would love you enough
to share his music with anyone is a beautiful thing." -- Duane Allman