off = (uint32) strtoul(str + len1 + 1, NULL, 16);
result = (XLogRecPtr) ((uint64) id << 32) | off;
- PG_RETURN_PG_LSN(result);
+ PG_RETURN_LSN(result);
}
Datum
pg_lsn_out(PG_FUNCTION_ARGS)
{
- XLogRecPtr lsn = (XLogRecPtr) PG_GETARG_PG_LSN(0);
+ XLogRecPtr lsn = (XLogRecPtr) PG_GETARG_LSN(0);
char buf[MAXPG_LSNLEN + 1];
char *result;
uint32 id, off;
XLogRecPtr result;
result = pq_getmsgint64(buf);
- PG_RETURN_PG_LSN(result);
+ PG_RETURN_LSN(result);
}
Datum
pg_lsn_send(PG_FUNCTION_ARGS)
{
- XLogRecPtr lsn = (XLogRecPtr) PG_GETARG_PG_LSN(0);
+ XLogRecPtr lsn = (XLogRecPtr) PG_GETARG_LSN(0);
StringInfoData buf;
pq_begintypsend(&buf);
Datum
pg_lsn_eq(PG_FUNCTION_ARGS)
{
- XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_PG_LSN(0);
- XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_PG_LSN(1);
+ XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_LSN(0);
+ XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_LSN(1);
PG_RETURN_BOOL(lsn1 == lsn2);
}
Datum
pg_lsn_ne(PG_FUNCTION_ARGS)
{
- XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_PG_LSN(0);
- XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_PG_LSN(1);
+ XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_LSN(0);
+ XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_LSN(1);
PG_RETURN_BOOL(lsn1 != lsn2);
}
Datum
pg_lsn_lt(PG_FUNCTION_ARGS)
{
- XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_PG_LSN(0);
- XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_PG_LSN(1);
+ XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_LSN(0);
+ XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_LSN(1);
PG_RETURN_BOOL(lsn1 < lsn2);
}
Datum
pg_lsn_gt(PG_FUNCTION_ARGS)
{
- XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_PG_LSN(0);
- XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_PG_LSN(1);
+ XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_LSN(0);
+ XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_LSN(1);
PG_RETURN_BOOL(lsn1 > lsn2);
}
Datum
pg_lsn_le(PG_FUNCTION_ARGS)
{
- XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_PG_LSN(0);
- XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_PG_LSN(1);
+ XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_LSN(0);
+ XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_LSN(1);
PG_RETURN_BOOL(lsn1 <= lsn2);
}
Datum
pg_lsn_ge(PG_FUNCTION_ARGS)
{
- XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_PG_LSN(0);
- XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_PG_LSN(1);
+ XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_LSN(0);
+ XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_LSN(1);
PG_RETURN_BOOL(lsn1 >= lsn2);
}
Datum
pg_lsn_mi(PG_FUNCTION_ARGS)
{
- XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_PG_LSN(0);
- XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_PG_LSN(1);
+ XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_LSN(0);
+ XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_LSN(1);
char buf[256];
Datum result;
- /* Negative results are not allowed. */
+ /* Output could be as large as plus or minus 2^63 - 1. */
if (lsn1 < lsn2)
- ereport(ERROR,
- (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
- errmsg("transaction log location out of range")));
+ snprintf(buf, sizeof buf, "-" UINT64_FORMAT, lsn2 - lsn1);
+ else
+ snprintf(buf, sizeof buf, UINT64_FORMAT, lsn1 - lsn2);
/* Convert to numeric. */
- snprintf(buf, sizeof buf, UINT64_FORMAT, lsn1 - lsn2);
result = DirectFunctionCall3(numeric_in,
CStringGetDatum(buf),
ObjectIdGetDatum(0),
#define PG_GETARG_CHAR(n) DatumGetChar(PG_GETARG_DATUM(n))
#define PG_GETARG_BOOL(n) DatumGetBool(PG_GETARG_DATUM(n))
#define PG_GETARG_OID(n) DatumGetObjectId(PG_GETARG_DATUM(n))
-#define PG_GETARG_PG_LSN(n) DatumGetPgLsn(PG_GETARG_DATUM(n))
+#define PG_GETARG_LSN(n) DatumGetLSN(PG_GETARG_DATUM(n))
#define PG_GETARG_POINTER(n) DatumGetPointer(PG_GETARG_DATUM(n))
#define PG_GETARG_CSTRING(n) DatumGetCString(PG_GETARG_DATUM(n))
#define PG_GETARG_NAME(n) DatumGetName(PG_GETARG_DATUM(n))
#define PG_RETURN_CHAR(x) return CharGetDatum(x)
#define PG_RETURN_BOOL(x) return BoolGetDatum(x)
#define PG_RETURN_OID(x) return ObjectIdGetDatum(x)
-#define PG_RETURN_PG_LSN(x) return PgLsnGetDatum(x)
+#define PG_RETURN_LSN(x) return LSNGetDatum(x)
#define PG_RETURN_POINTER(x) return PointerGetDatum(x)
#define PG_RETURN_CSTRING(x) return CStringGetDatum(x)
#define PG_RETURN_NAME(x) return NameGetDatum(x)