Re: Comparing txid_current() to xmin

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Mike Lewis <mikelikespie(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Comparing txid_current() to xmin
Date: 2012-11-07 02:10:19
Message-ID: 20121107021018.GB6348@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Mike Lewis escribió:
> I am trying to make a trigger that updates a row once and only once per
> transaction (even if this trigger gets fired multiple times). The general
> idea is that for a user we have a version number. When we modify the
> user's data, the version number is incremented then set on the object. We
> only need to increment the version number once.
>
> I am thinking about doing something like:
>
> update user
> set version=version+1
> where txid_current() != xmin and user_id = 352395;

Uh, txid_current returns a 64 bit value, whereas xmin only stores the 32
least significant bits. They would certainly differ after a xid
wraparound.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mike Lewis 2012-11-07 02:35:46 Re: Comparing txid_current() to xmin
Previous Message Craig Ringer 2012-11-07 01:54:37 Re: Tuning / performance questions