Re: PREPARE and transactions

Поиск
Список
Период
Сортировка
От Merlin Moncure
Тема Re: PREPARE and transactions
Дата
Msg-id 6EE64EF3AB31D5448D0007DD34EEB34101AE74@Herge.rcsinc.local
обсуждение исходный текст
Ответ на PREPARE and transactions  ("Jeroen T. Vermeulen" <jtv@xs4all.nl>)
Ответы Re: PREPARE and transactions  (Christopher Kings-Lynne <chriskl@familyhealth.com.au>)
Список pgsql-hackers
> Now, here's a scenario that has us worried:
>
> BEGIN
>   PREPARE foo AS ...
>   ...            [error]
>   DEALLOCATE foo     [fails: already aborted by previous error]
> ABORT
> BEGIN
>   PREPARE foo AS ...      [fails: foo is already defined!]
>   EXECUTE foo        [fails: already aborted by previous error]
> COMMIT            [fails: already aborted by previous
error]

Part of the problem is that PREPARE has no provision to overwrite an
existing plan (CREATE OR REPLACE).  I run into this all the time because
I make heavy use of prepared statements to emulate an ISAM file system.
I have to jump through hoops to keep track of what statements are
already prepared to keep from bouncing the current transaction.

However, at least for me, nested x basically solves this problem.  I'll
just always wrap the prepare statement with a sub-transaction and
commit/rollback as necessary.  This is odd because the rollback does
nothing other than guard the following statements from the prepare
failure to execute.
So, you do:

BEGIN BEGIN   PREPARE foo AS ... COMMIT/ROLLBACK ...            [error] DEALLOCATE foo     [fails: already aborted by
previouserror] 
ABORT
BEGIN BEGIN   PREPARE foo AS ...  [fails: foo is already defined!] COMMIT/ROLLBACK EXECUTE foo        [will now always
runif prepare is aborted] 
COMMIT            [commit executes]

To me, this is good style and it looks like nested x is going to make
7.5.  I have no opinion on whether rollback should affect
prepare/deallocate.

Merlin



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

Предыдущее
От: Josh Berkus
Дата:
Сообщение: Re: 7.5-dev, pg_dumpall, dollarquoting
Следующее
От: Alexander Cohen
Дата:
Сообщение: Re: creating a cluster