Re: #Personal#: Reg: Multiple queries in a transaction

Поиск
Список
Период
Сортировка
От David G Johnston
Тема Re: #Personal#: Reg: Multiple queries in a transaction
Дата
Msg-id 1424332828934-5838540.post@n5.nabble.com
обсуждение исходный текст
Ответ на Re: #Personal#: Reg: Multiple queries in a transaction  (David G Johnston <david.g.johnston@gmail.com>)
Список pgsql-general
David G Johnston wrote
>
> Medhavi Mahansaria wrote
>> Hi Bill,
>>
>> Thanks!
>>
>> But savepoint concept will not work for me as desired.
>>
>> Is there any other way apart from SAVEPOINT that can be incorporated.
>>
>> I am not using a script. I am writing a c++ program.
>>
>> My problem is that I have 2 cases:
>>
>> Case 1: When Q2 fails (we delete the error), i want to continue to Q3 and
>> commit changes done by Q1 and Q3 once Q3 has executed successfully.
>>
>> Case 2: When Q2 fails, I want it to throw an error. and rollback the
>> changes made by Q1 and not proceed to Q3 at all.
>>
>> Note: This is just a small example. I need a solution for an entire
>> application which follows the same concept across multiple queries.
>>
>> How can I incorporate this?
> Forgo transactions or use savepoints.  Those are your tools.  If you
> cannot find a way to solve your problem with those tools you either need
> to choose, or build, a different toolbox or explain your actual problem in
> greater detail so that others can see if there are solutions you are
> overlooking.
>
> Or redefine your problem.
>
> David J.

You might be able to write the code in pl/pgsql and just call it from your
application.  You have a bit more options for flow control in that compared
to pure SQL.

http://www.postgresql.org/docs/9.3/static/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING

David J.



--
View this message in context:
http://postgresql.nabble.com/Personal-Reg-Multiple-queries-in-a-transaction-tp5838427p5838540.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


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

Предыдущее
От: David G Johnston
Дата:
Сообщение: Re: #Personal#: Reg: Multiple queries in a transaction
Следующее
От: Andrew Sullivan
Дата:
Сообщение: Re: #Personal#: Reg: Multiple queries in a transaction