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