X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 559293AC5BB for ; Tue, 28 Dec 2004 15:51:35 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 97069-03 for ; Tue, 28 Dec 2004 15:51:22 +0000 (GMT) Received: from smtp.lewczuk.com (118.224.149.195.tld.pl [195.149.224.118]) by svr1.postgresql.org (Postfix) with SMTP id 6CD783AC43C for ; Tue, 28 Dec 2004 15:51:24 +0000 (GMT) Received: (qmail 4122 invoked by uid 700); 28 Dec 2004 15:51:22 -0000 Received: from linux.samar.pl (HELO ?192.168.1.17?) (marek@lewczuk.com@62.233.139.198) by 118.224.149.195.tld.pl with SMTP; 28 Dec 2004 15:51:22 -0000 Message-ID: <41D18108.1080901@lewczuk.com> Date: Tue, 28 Dec 2004 16:51:36 +0100 From: Marek Lewczuk User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: jzobel@heute-morgen.de Cc: Lista dyskusyjna pgsql-general Subject: Re: Get current trasanction id References: <41CFCD69.6010503@lewczuk.com> <20041227145406.GA73681@winnie.fuhr.org> <41D06889.9040503@lewczuk.com> <1104246353.22419.216.camel@localhost> In-Reply-To: <1104246353.22419.216.camel@localhost> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.074 tagged_above=0 required=5 tests=FORGED_RCVD_HELO, RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200412/1236 X-Sequence-Number: 70848 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