On 08/28/2014 04:22 AM, Ramesh T wrote:
OK.. i created a function for delete customer from different tables in
single database.
i want rollback..
my question:
where i need to place rollback ,with in a
function along with deletion statements..? or after run the function ..?
i do not need commit..
If you want to invoke an explicit ROLLBACK then you will need an
explicit BEGIN, which means you will need an explicit COMMIT to have the
operation succeed.
For the reasons why see here:
http://www.postgresql.org/docs/9.3/static/tutorial-transactions.html
please let me know..
First, the function code would be nice to see or at least a heads up on
what language you are using.
Second, there are no transactions inside functions. In the case of
plpgsql you can use EXCEPTIONs to mimic the behavior:
http://www.postgresql.org/docs/9.3/static/plpgsql-structure.html
"t is important not to confuse the use of BEGIN/END for grouping
statements in PL/pgSQL with the similarly-named SQL commands for
transaction control. PL/pgSQL's BEGIN/END are only for grouping; they do
not start or end a transaction. Functions and trigger procedures are
always executed within a transaction established by an outer query —
they cannot start or commit that transaction, since there would be no
context for them to execute in. However, a block containing an EXCEPTION
clause effectively forms a subtransaction that can be rolled back
without affecting the outer transaction. For more about that see Section
40.6.6."
http://www.postgresql.org/docs/9.3/static/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING
--
Adrian Klaver
adrian.klaver@xxxxxxxxxxx
--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general