Re: Pending trigger events on ALTER TABLE in 8.3

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Pending trigger events on ALTER TABLE in 8.3
Дата
Msg-id 3944.1312239528@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Pending trigger events on ALTER TABLE in 8.3  ("Reuven M. Lerner" <reuven@lerner.co.il>)
Ответы Re: Pending trigger events on ALTER TABLE in 8.3  ("Reuven M. Lerner" <reuven@lerner.co.il>)
Список pgsql-general
"Reuven M. Lerner" <reuven@lerner.co.il> writes:
> Reports=# \d "RecipeNumericParameterSnapshot"
> Foreign-key constraints:
>      "RecipeNumericParameterSnapshot_RecipeSnapshot_fk" FOREIGN KEY
> ("RecipeSnapshotID") REFERENCES "RecipeSnapshot"("ID") ON DELETE CASCADE
> DEFERRABLE INITIALLY DEFERRED

OK, this is about what I was expecting to find.  Either an INSERT or
UPDATE on RecipeNumericParameterSnapshot, or an UPDATE or DELETE on
RecipeSnapshot, will result in queueing a trigger event on
RecipeNumericParameterSnapshot.  And since it's DEFERRED, that trigger
isn't fired right away in the command that queues it; it's held till end
of transaction.  (Depending on your PG version, an UPDATE that doesn't
actually change any FK-involved columns might not queue a trigger event.
But I don't remember how smart 8.3 is about that.)

One possible answer is to do SET CONSTRAINTS ALL IMMEDIATE before trying
the ALTER TABLE, so that any pending foreign key checks are done at that
time.

BTW, just to be clear: these must be DML events occurring in the same
transaction that later tries the ALTER.  Events in a concurrent
transaction would not result in this behavior, because the ALTER would
just block until the concurrent transaction finished.

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Rodrigo Gonzalez
Дата:
Сообщение: Re: why cannot UNION both SELECT and SHOW?
Следующее
От: "Reuven M. Lerner"
Дата:
Сообщение: Re: Pending trigger events on ALTER TABLE in 8.3