Re: Comparing txid_current() to xmin

From: Andres Freund <andres(at)anarazel(dot)de>
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 08:21:04
Message-ID: 20121107082104.GA6740@anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Nov 06, 2012 at 02:55:40PM -0800, Mike Lewis wrote:
> 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;
>
>
> So I guess my questions are:
>
> How dirty is this?
> Will I run into issues?

It won't work in the presenence of subtransactions and is a bit more
complicated if you inserted the row in the same transaction.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Achilleas Mantzios 2012-11-07 08:26:46 Re: Memory issue on FreeBSD
Previous Message Achilleas Mantzios 2012-11-07 08:16:43 Re: Memory issue on FreeBSD