Retrieving the transaction id ... 
Author Message
 Retrieving the transaction id ...

Is there a standard way for retrieving the current transaction id? If
there is not here is a brief function which does the job:

#include "postgres.h"
#include "access/xact.h"

Datum
getxid(PG_FUNCTION_ARGS)
{
        TransactionId xid = GetCurrentTransactionId();
        PG_RETURN_INT32((int32) xid);

Quote:
}

And here is the SQL code for adding it to the database:
DROP FUNCTION getxid();

CREATE FUNCTION getxid()
        RETURNS int4
        AS '/home/hs/datatype/transaction/libgetxid.so'
        LANGUAGE 'C';

SELECT getxid();

A function like that can be useful for logging purposes. Assume a table
where a list of all SQL commands sent to the server is stored. To
distinguish the transactions the statements belong do retrieving the
transaction id might be useful.
I have tested the function above on my UNIX maschine and it seems to
work well.

I'd be pleased if anybody could integrate a function like that in
PostgreSQL's core distribution.

    Hans

--
{*filter*}tec Geschwinde &. Schoenig
Ludo-Hartmannplatz 1/14; A-1160 Wien
Tel.: +43/1/913 68 09 oder +43/664/233 90 75
URL: www.{*filter*}tec.at oder http://postgres.{*filter*}tec.at



Sun, 25 Jul 2004 06:40:52 GMT
 
 [ 1 post ] 

 Relevant Pages 

1. Transaction Id/ Connection Id

2. Transaction ID in a double entry accounting transaction journal

3. Transactions in functions ( was Re: transactions, serial ids, and JDBC)

4. Retrieve the ID from the newly added record?

5. Retrieving record ID from first part of trigger

6. SQL statement...retrieving one row for each id

7. Cannot retrieve ID of new inserted record

8. database entry and retrieving the unique ID

9. Retrieving Automatic ID of new record

10. Retrieving ID field when doing an INSERT

11. Retrieving the user id

12. Retrieving ID problem


 
Powered by phpBB® Forum Software