Thread: Libpq and transactions
Hi! I have a question about how transaction behaves in libpq library. It is very clear in doc that PQexec treats each command (which could comprise of more than one sql command) as a single transactions. Does PQexecParams() and PQexecPrepared() also behaves the same? Is there a way to send multiple sql commands separately through libpq library and rollback if nth command fails. For example, Can I insert 5 rows using PQexecParams() and rollback all 5 rows if sixth insert fails? Regards, Brijesh
On 2004-07-07 01:50, Użytkownik Brijesh Shrivastav napisał: > Hi! > > I have a question about how transaction behaves in libpq library. > It is very clear in doc that PQexec treats each command (which could > comprise of more than one sql command) as a single transactions. Not exactly. PQexec treats each command as a single transaction only when you don't add "begin" before your query. If you add "begin" before first query - it will finish after "commit" or "rollback". Regards, Tomasz Myrta
Thanks for clarification! I got confused with document wording. Brijesh Shrivastav -----Original Message----- From: Tomasz Myrta [mailto:jasiek@klaster.net] Sent: Wednesday, July 07, 2004 12:05 AM To: Brijesh Shrivastav Cc: PostgreSQL Interfaces Subject: Re: [INTERFACES] Libpq and transactions On 2004-07-07 01:50, Użytkownik Brijesh Shrivastav napisał: > Hi! > > I have a question about how transaction behaves in libpq library. > It is very clear in doc that PQexec treats each command (which could > comprise of more than one sql command) as a single transactions. Not exactly. PQexec treats each command as a single transaction only when you don't add "begin" before your query. If you add "begin" before first query - it will finish after "commit" or "rollback". Regards, Tomasz Myrta ---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html