pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedtransactions within stored procedures
2+ messages / 2 participants
[nested] [flat]
* transactions within stored procedures
@ 2000-07-14 16:02 Nathan Young <nyoung@silcom.com>
0 siblings, 0 replies; 2+ messages in thread
From: Nathan Young @ 2000-07-14 16:02 UTC (permalink / raw)
To: pgsql-sql
Hi.
Please correct me if this is off topic for the group. On looking
through the available postgres mailing lists, this seemed the most
appropriate for my question.
Transactions are important to my application. I was scripting in perl
with autocommit turned off, issuing commits when appropriate. As I
moved more of my logic into stored procedures, I looked for
documentation on how transactions work in stored procedures and I
couldn't find any! I'm using pl/pgsql right now but would happily use
pg/perl...
By trial and error I established that a SP wraps everything it does in
one transaction, including anything from stored procedures it calls.
So here is my question: Is there any way for me to control when
transactions are committed or rolled back within stored procedures? Is
there an equivalent to turning autocommit off, in other words doing each
statement in its own transaction? Or is there a command to let me
commit whenever I want to? Also, can I roll back a transaction based on
programmatically defined logic, or only on a database error?
Thanks in advance...
--------------------->Nathan
--
¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤
Nathan Young
nathan@ncyoung.com
(805) 686-2830
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: transactions within stored procedures
@ 2000-07-14 16:19 Thomas Mack <mack@ips.cs.tu-bs.de>
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Mack @ 2000-07-14 16:19 UTC (permalink / raw)
To: pgsql-sql
>
>By trial and error I established that a SP wraps everything it does in
>one transaction, including anything from stored procedures it calls.
>
>So here is my question: Is there any way for me to control when
>transactions are committed or rolled back within stored procedures? Is
When you invoke a procedure, this invocation is part of a transaction.
You cannot nest transactions so far, as you intend, when you want to
commit or rollback inside of a procedure.
So, when you want your procedure to fail, you would raise an exception,
otherwise, you won't. The invoking program has to react on errors, as it
should do in other situations as well.
For example, select * from xyz fails with an error, when table xyz does
not exist. If you have this statement inside of a transaction, you
would normally react on the error (commit / rollback).
Thomas Mack
TU Braunschweig, Abt. Informationssysteme
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2000-07-14 16:19 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-07-14 16:02 transactions within stored procedures Nathan Young <nyoung@silcom.com>
2000-07-14 16:19 Re: transactions within stored procedures Thomas Mack <mack@ips.cs.tu-bs.de>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox