[GENERAL] PL/pgSQL equivalent to PQtransactionStatus?

2008-07-31 Thread Christophe
My apologies if this is in the docs and I missed it, but is there a  
PL/pgSQL function equivalent for the pglib function  
PQtransactionStatus (i.e., a way to find out if we're in an open  
transaction block, and if that transaction is in an error status)?


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] PL/pgSQL equivalent to PQtransactionStatus?

2008-07-31 Thread Richard Huxton

Christophe wrote:
My apologies if this is in the docs and I missed it, but is there a 
PL/pgSQL function equivalent for the pglib function PQtransactionStatus 
(i.e., a way to find out if we're in an open transaction block, and if 
that transaction is in an error status)?


A pl/pgsql function *always* executes within a transaction.

If an error occurs while that function is executing you can catch the 
exception (see the Trapping Errors section of the pl/pgsql docs).


If an error occurs before the function executes then no other statements 
will be executed.


HTH

--
  Richard Huxton
  Archonet Ltd

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] PL/pgSQL equivalent to PQtransactionStatus?

2008-07-31 Thread Christophe


On Jul 31, 2008, at 11:12 AM, Richard Huxton wrote:

A pl/pgsql function *always* executes within a transaction.


Indeed so.  What I'm looking for is a way of detecting if a  
transaction block has been opened (i.e., we're within a BEGIN).


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] PL/pgSQL equivalent to PQtransactionStatus?

2008-07-31 Thread Alvaro Herrera
Christophe wrote:

 On Jul 31, 2008, at 11:12 AM, Richard Huxton wrote:
 A pl/pgsql function *always* executes within a transaction.

 Indeed so.  What I'm looking for is a way of detecting if a transaction 
 block has been opened (i.e., we're within a BEGIN).

Why does it matter?

-- 
Alvaro Herrerahttp://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] PL/pgSQL equivalent to PQtransactionStatus?

2008-07-31 Thread Christophe


On Jul 31, 2008, at 11:49 AM, Alvaro Herrera wrote:

Why does it matter?


I'm attempting to clean out a connection that is in an unknown  
state (along the lines of what pgpool does when reusing an open  
connection).  Of course, I could just fire an ABORT down, but it  
seems nicer to avoid doing so if no transaction block is open.


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] PL/pgSQL equivalent to PQtransactionStatus?

2008-07-31 Thread Christophe


On Jul 31, 2008, at 11:49 AM, Alvaro Herrera wrote:

Why does it matter?


Ah, I see, deep confusing on my part regarding PL/pgSQL and  
tranasctions!  Ignore question. :)


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] PL/pgSQL equivalent to PQtransactionStatus?

2008-07-31 Thread Richard Huxton

Christophe wrote:


On Jul 31, 2008, at 11:12 AM, Richard Huxton wrote:

A pl/pgsql function *always* executes within a transaction.


Indeed so.  What I'm looking for is a way of detecting if a transaction 
block has been opened (i.e., we're within a BEGIN).


There is no difference between a transaction explicitly started with 
BEGIN...COMMIT and one wrapping a single statement.


What were you planning to do differently if a BEGIN was issued?

--
  Richard Huxton
  Archonet Ltd

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] PL/pgSQL equivalent to PQtransactionStatus?

2008-07-31 Thread Alvaro Herrera
Christophe wrote:

 On Jul 31, 2008, at 11:49 AM, Alvaro Herrera wrote:
 Why does it matter?

 I'm attempting to clean out a connection that is in an unknown state 
 (along the lines of what pgpool does when reusing an open connection).  
 Of course, I could just fire an ABORT down, but it seems nicer to avoid 
 doing so if no transaction block is open.

Maybe DISCARD ALL does what you want?

http://www.postgresql.org/docs/8.3/static/sql-discard.html

-- 
Alvaro Herrerahttp://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general