Re: How to check whether the row was modified by this transaction before?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Vlad Arkhipov <arhipov(at)dc(dot)baikal(dot)ru>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: How to check whether the row was modified by this transaction before?
Date: 2012-12-06 17:53:46
Message-ID: 6067.1354816426@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Vlad Arkhipov <arhipov(at)dc(dot)baikal(dot)ru> writes:
> In a BEFORE UPDATE trigger I need to know whether the row was previously
> modified by this transaction. Is it safe to use xmin and txid_current()
> for this purpose (xmin is 32-bit txid type but txid_current() returns
> 64-bit bigint).

> IF OLD.xmin = txid_current() THEN

Comparing to txid_current() mod 2^32 would probably work, but note this
will not think that subtransactions or parent transactions are "this
transaction", so any use of savepoints or plpgsql exception blocks is
likely to cause headaches. Why do you think you need to know this?

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2012-12-06 17:56:53 Re: Commits 8de72b and 5457a1 (COPY FREEZE)
Previous Message Alvaro Herrera 2012-12-06 17:53:44 Re: Fix for pg_upgrade status display