1/*-------------------------------------------------------------------------
4 * Operations for the pg_lsn datatype.
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/backend/utils/adt/pg_lsn.c
12 *-------------------------------------------------------------------------
17#include "utils/fmgrprotos.h"
21 #define MAXPG_LSNLEN 17
22 #define MAXPG_LSNCOMPONENT 8
24/*----------------------------------------------------------
25 * Formatting and conversion routines.
26 *---------------------------------------------------------*/
29 * Internal version of pg_lsn_in() with support for soft error reporting.
40 /* Sanity check input format. */
41 len1 = strspn(
str,
"0123456789abcdefABCDEF");
45 len2 = strspn(
str + len1 + 1,
"0123456789abcdefABCDEF");
51 off = (
uint32) strtoul(
str + len1 + 1, NULL, 16);
52 result = ((
uint64)
id << 32) | off;
58 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
59 errmsg(
"invalid input syntax for type %s: \"%s\"",
108/*----------------------------------------------------------
109 * Operators for PostgreSQL LSNs
110 *---------------------------------------------------------*/
184/* btree index opclass support */
199/* hash index opclass support */
203 /* We can use hashint8 directly */
214/*----------------------------------------------------------
215 * Arithmetic operators on PostgreSQL LSNs.
216 *---------------------------------------------------------*/
226 /* Output could be as large as plus or minus 2^63 - 1. */
232 /* Convert to numeric. */
242 * Add the number of bytes to pg_lsn, giving a new pg_lsn.
243 * Must handle both positive and negative numbers of bytes.
256 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
257 errmsg(
"cannot add NaN to pg_lsn")));
259 /* Convert to numeric */
266 /* Add two numerics */
271 /* Convert to pg_lsn */
276 * Subtract the number of bytes from pg_lsn, giving a new pg_lsn.
277 * Must handle both positive and negative numbers of bytes.
290 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
291 errmsg(
"cannot subtract NaN from pg_lsn")));
293 /* Convert to numeric */
300 /* Subtract two numerics */
305 /* Convert to pg_lsn */
Datum numeric_sub(PG_FUNCTION_ARGS)
Datum numeric_in(PG_FUNCTION_ARGS)
bool numeric_is_nan(Numeric num)
Datum numeric_add(PG_FUNCTION_ARGS)
Datum numeric_pg_lsn(PG_FUNCTION_ARGS)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
#define PG_RETURN_BYTEA_P(x)
#define DirectFunctionCall2(func, arg1, arg2)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define DirectFunctionCall1(func, arg1)
#define PG_GETARG_CSTRING(n)
#define PG_RETURN_INT32(x)
#define DirectFunctionCall3(func, arg1, arg2, arg3)
#define PG_RETURN_BOOL(x)
Datum hashint8extended(PG_FUNCTION_ARGS)
Datum hashint8(PG_FUNCTION_ARGS)
char * pstrdup(const char *in)
#define PG_GETARG_NUMERIC(n)
static Datum NumericGetDatum(Numeric X)
Datum pg_lsn_ne(PG_FUNCTION_ARGS)
Datum pg_lsn_eq(PG_FUNCTION_ARGS)
Datum pg_lsn_cmp(PG_FUNCTION_ARGS)
Datum pg_lsn_out(PG_FUNCTION_ARGS)
Datum pg_lsn_smaller(PG_FUNCTION_ARGS)
Datum pg_lsn_send(PG_FUNCTION_ARGS)
#define MAXPG_LSNCOMPONENT
Datum pg_lsn_le(PG_FUNCTION_ARGS)
Datum pg_lsn_in(PG_FUNCTION_ARGS)
Datum pg_lsn_pli(PG_FUNCTION_ARGS)
XLogRecPtr pg_lsn_in_safe(const char *str, Node *escontext)
Datum pg_lsn_mii(PG_FUNCTION_ARGS)
Datum pg_lsn_hash(PG_FUNCTION_ARGS)
Datum pg_lsn_ge(PG_FUNCTION_ARGS)
Datum pg_lsn_hash_extended(PG_FUNCTION_ARGS)
Datum pg_lsn_gt(PG_FUNCTION_ARGS)
Datum pg_lsn_larger(PG_FUNCTION_ARGS)
Datum pg_lsn_recv(PG_FUNCTION_ARGS)
Datum pg_lsn_mi(PG_FUNCTION_ARGS)
Datum pg_lsn_lt(PG_FUNCTION_ARGS)
void syntax_error(const char *source, int lineno, const char *line, const char *command, const char *msg, const char *more, int column)
static Datum ObjectIdGetDatum(Oid X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
struct StringInfoData * StringInfo
#define LSN_FORMAT_ARGS(lsn)
#define InvalidXLogRecPtr