Re: Get current trasanction id

From: Marek Lewczuk <newsy(at)lewczuk(dot)com>
To: jzobel(at)heute-morgen(dot)de
Cc: Lista dyskusyjna pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Get current trasanction id
Date: 2004-12-28 15:51:36
Message-ID: 41D18108.1080901@lewczuk.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

Joachim Zobel napisał(a):
> Am Mo, den 27.12.2004 schrieb Marek Lewczuk um 20:54:
>
>>Michael Fuhr napisał(a):
>>
>>>Why do you want the transaction ID? What problem are you trying
>>>to solve?
>>>
>>
>>I've already solved the problem - I found somewhere on the web a very
>>simple C function, which returns transaction id. I need transaction id
>>for plperl functions setVar, getVar (using $_SHARED array). Functions
>>can write/read variables which are available either for connection or
>>transaction.
>
>
> It would be nice to have that in pgplsql. I once needed a transaction Id
> in oracle for a historisation trigger. It saves before copies of the
> modified records on a per transaction basis.
As I wrote before you can have it in plpgsql - you just need to install
special c function as e.g getCurrentTransactionId() and you will be able
to get id from within plpgsql - but I agree that this function should be
in base SQL functions or at least in contrib modules.

C function is very simple:

getcurrenttransactionid.c:
#include "postgres.h"
#include "access/xact.h"

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

getcurrenttransactionid.sql:
SET search_path = public;

CREATE FUNCTION getCurrentTransactionId()
RETURNS integer
AS 'MODULE_PATHNAME'
LANGUAGE 'c';

Regards,

Marek Lewczuk

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Greg Stark 2004-12-28 17:50:41 Re: Long-running performance (MVCC, Vacuum, etc.) - Any fix?
Previous Message Tom Lane 2004-12-28 15:13:14 Re: 8.0 rc2 Problem

Browse pgsql-sql by date

  From Date Subject
Next Message Nathan Pickett 2004-12-28 17:12:03 Making a prepared statement in a stored procedure
Previous Message Joachim Zobel 2004-12-28 15:05:53 Re: Get current trasanction id