*** pgsql/src/backend/commands/trigger.c Sun Sep 29 18:56:41 2002 --- pgsql/src/backend/commands/trigger.c.new Sun Sep 29 22:54:19 2002 *************** *** 91,98 **** if (stmt->constrrel != NULL) constrrelid = RangeVarGetRelid(stmt->constrrel, false); ! else ! constrrelid = InvalidOid; if (rel->rd_rel->relkind != RELKIND_RELATION) elog(ERROR, "CreateTrigger: relation \"%s\" is not a table", --- 91,136 ---- if (stmt->constrrel != NULL) constrrelid = RangeVarGetRelid(stmt->constrrel, false); ! else { ! /* ! * If this trigger is a constraint (and a foreign key one) ! * then we really need a constrrelid. Since we don't have ! * one, we'll try to generate one from the argument information. ! */ ! if (stmt->isconstraint) { ! void *elem = NULL; ! bool needconstrrelid = false; ! if (strncmp(strVal(lfirst(stmt->funcname)), "RI_FKey_check", 13) == 0) { ! /* A trigger on FK table. */ ! needconstrrelid = true; ! if (length(stmt->args) > RI_PK_RELNAME_ARGNO) ! elem=nth(RI_PK_RELNAME_ARGNO, stmt->args); ! } ! else if (strncmp(strVal(lfirst(stmt->funcname)), "RI_FKey", 7) == 0) { ! /* A trigger on PK table. */ ! needconstrrelid = true; ! if (length(stmt->args) > RI_FK_RELNAME_ARGNO) ! elem=nth(RI_FK_RELNAME_ARGNO, stmt->args); ! } ! if (elem != NULL) { ! RangeVar * rel = makeNode(RangeVar); ! rel->catalogname = NULL; ! rel->schemaname = NULL; ! rel->relname = strVal(elem); ! ! constrrelid = RangeVarGetRelid(rel, false); ! } ! else { ! constrrelid = InvalidOid; ! } ! if (needconstrrelid && constrrelid == InvalidOid) { ! elog(ERROR, "Unable to find table for constraint \"%s\"", stmt->trigname); ! } ! } ! else { ! constrrelid = InvalidOid; ! } ! } if (rel->rd_rel->relkind != RELKIND_RELATION) elog(ERROR, "CreateTrigger: relation \"%s\" is not a table",