* via functions such as SubTransGetTopmostTransaction().
*
*
- * Copyright (c) 2003-2015, PostgreSQL Global Development Group
+ * Copyright (c) 2003-2017, PostgreSQL Global Development Group
* Author: Jan Wieck, Afilias USA INC.
* 64-bit txids: Marko Kreen, Skype Technologies
*
/* txid will be signed int8 in database, so must limit to 63 bits */
-#define MAX_TXID ((uint64) INT64_MAX)
+#define MAX_TXID ((uint64) PG_INT64_MAX)
/* Use unsigned variant internally */
typedef uint64 txid;
static void
sort_snapshot(TxidSnapshot *snap)
{
- txid last = 0;
- int nxip, idx1, idx2;
+ txid last = 0;
+ int nxip,
+ idx1,
+ idx2;
if (snap->nxip > 1)
{
return buf_finalize(buf);
bad_format:
- elog(ERROR, "invalid input for txid_snapshot: \"%s\"", str_start);
- return NULL;
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("invalid input syntax for type %s: \"%s\"",
+ "txid_snapshot", str_start)));
+ return NULL; /* keep compiler quiet */
}
/*
PG_RETURN_INT64(val);
}
+/*
+ * Same as txid_current() but doesn't assign a new xid if there isn't one
+ * yet.
+ */
+Datum
+txid_current_if_assigned(PG_FUNCTION_ARGS)
+{
+ txid val;
+ TxidEpoch state;
+ TransactionId topxid = GetTopTransactionIdIfAny();
+
+ if (topxid == InvalidTransactionId)
+ PG_RETURN_NULL();
+
+ load_xid_epoch(&state);
+
+ val = convert_xid(topxid, &state);
+
+ PG_RETURN_INT64(val);
+}
+
/*
* txid_current_snapshot() returns txid_snapshot
*
PG_RETURN_POINTER(snap);
bad_format:
- elog(ERROR, "invalid snapshot data");
- return (Datum) NULL;
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
+ errmsg("invalid external txid_snapshot data")));
+ PG_RETURN_POINTER(NULL); /* keep compiler quiet */
}
/*