Re: Complex transactions without using plPgSQL Functions. It is possible?

Поиск
Список
Период
Сортировка
От Chris Angelico
Тема Re: Complex transactions without using plPgSQL Functions. It is possible?
Дата
Msg-id CAPTjJmrRZ-xO6qvOwo6MpOH+BeEWpBy77_8TmVzrMx2bve0cBQ@mail.gmail.com
обсуждение исходный текст
Ответ на Complex transactions without using plPgSQL Functions. It is possible?  (Andre Lopes <lopes80andre@gmail.com>)
Ответы Re: Complex transactions without using plPgSQL Functions. It is possible?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
On Wed, Mar 7, 2012 at 6:30 AM, Andre Lopes <lopes80andre@gmail.com> wrote:
> I'm writing a web application that uses PostgreSQL and I need to do
> some operations where I read/write to 3 tables in the same
> transaction.

Is what you're looking for simply the "begin transaction"[1] and
"commit"[2] commands? With those, you can write your code to do
whatever it likes, and it'll still be all one transaction.

With some caveats, of course, but if all you're doing is INSERT /
DELETE / UPDATE, you'll be fully protected by the transaction
boundaries (eg if your script dies unexpectedly in the middle, the
whole thing will be rolled back, all those usual safeties).

As a side point: Is it possible to disable Postgres's default
autocommit behavior and have it automatically open a transaction on
connection and after commit/rollback? That's what I grew up on with
DB2 - you do some work, then you commit, then you do more work, then
you commit, but never have to say "and begin a transaction too".

Chris Angelico
[1] http://www.postgresql.org/docs/current/static/sql-begin.html
[2] http://www.postgresql.org/docs/current/static/sql-commit.html

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

Предыдущее
От: Matteo Sgalaberni
Дата:
Сообщение: corrupted table postgresql 8.3
Следующее
От: Tomas Vondra
Дата:
Сообщение: Re: corrupted table postgresql 8.3