Re: "xmin" system column - Mailing list pgsql-general

From Eric B. Ridge
Subject Re: "xmin" system column
Date
Msg-id 4710D15A-3EF0-4559-A061-27ABB1594BA3@tcdi.com
Whole thread Raw
In response to Re: "xmin" system column  (Michael Fuhr <mike@fuhr.org>)
Responses Re: "xmin" system column  (Christian Kratzer <ck-lists@cksoft.de>)
List pgsql-general
On Jan 26, 2006, at 5:22 PM, Michael Fuhr wrote:
> I suppose a sequence is out of the question?  Too easy to get it
> wrong?

Well, I just wanted to avoid embedding this idea into my
application.  Would rather Postgres take care of it for me.

> Not in the standard installation, but I think a C function that
> returns GetTopTransactionId() should work.  It's trivial to write
> and examples have been posted before; search the archives.

Hmm.  I also see GetCurrentTransactionStartTimestamp() in xact.h.
That could work as a mostly-unique identifier.  Its value could
survive dumps (assuming clock is set correctly!) and a little wrapper
around it could be used by triggers or by default column values.

Futher reading in xact.c says:
    /*
     * This is the value of now(), ie, the transaction start time.
     * This does not change as we enter and exit subtransactions, so we
don't
     * keep it inside the TransactionState stack.
     */
    static TimestampTz xactStartTimestamp;

<long pause>

hahaha, *blush*.  I could just use "now()", right?  pg8.1 docs say
that now()/CURRENT_TIMESTAMP "return the start time of the current
transaction; their values do not change during the transaction".  I
could use a composite of (now(), GetTopTransctionId()) to assume
batch uniqueness.

eric

pgsql-general by date:

Previous
From: vishal saberwal
Date:
Subject: Re: SYNTAX ERROR at or near SQLSTATE
Next
From: Bob Pawley
Date:
Subject: Re: Arrays