ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
compatibility.h File Reference

PostgreSQL cross-version compatibility shims for ProvSQL. More...

#include "postgres.h"
#include "nodes/pg_list.h"
Include dependency graph for compatibility.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define F_COUNT_ANY   2147
 OID of count(*) / count(any) aggregate function (pre-PG 14).
#define F_COUNT_   2803
 OID of count() aggregate function (pre-PG 14).
#define F_SUM_INT4   2108
 OID of sum(int4) aggregate function (pre-PG 14).
#define TYPALIGN_INT   'i'
 Alignment codes for the array routines (construct_array / deconstruct_array).
#define TYPALIGN_CHAR   'c'
#define F_ARRAY_AGG_ANYNONARRAY   2335
 OID of the array_agg(anynonarray) aggregate (pre-PG 14).

Functions

static List * my_list_delete_cell (List *list, ListCell *cell, ListCell *prev)
 Version-agnostic wrapper around list_delete_cell().
static ListCell * my_lnext (const List *l, const ListCell *c)
 Version-agnostic wrapper around lnext().
List * list_insert_nth (List *list, int pos, void *datum)
 Insert datum at position pos in list (PG < 13 backport).

Detailed Description

PostgreSQL cross-version compatibility shims for ProvSQL.

ProvSQL supports a range of PostgreSQL major versions. This header centralises the small API differences between those versions so that the rest of the codebase can call a single, stable interface.

Currently handled differences:

  • List API (13+): list_delete_cell() and lnext() gained or lost a prev argument between PostgreSQL 12 and 13. The my_list_delete_cell() and my_lnext() wrappers hide this.
  • list_insert_nth() (< 13): In PostgreSQL 12 and earlier the list implementation was a linked list and this helper did not exist; compatibility.c provides a backport.
  • Predefined function OIDs (< 14): The F_COUNT_ANY, F_COUNT_, and F_SUM_INT4 macros were introduced in PostgreSQL
    1. Stable OID values for older releases are defined here.
  • list_make5() (13): existed pre-13, dropped by the PG13 list rewrite, re-added in PG14; backported for the PG13 gap as a macro over list_make4() + lappend().

Definition in file compatibility.h.

Macro Definition Documentation

◆ F_ARRAY_AGG_ANYNONARRAY

#define F_ARRAY_AGG_ANYNONARRAY   2335

OID of the array_agg(anynonarray) aggregate (pre-PG 14).

The F_ARRAY_AGG_ANYNONARRAY macro only exists since PostgreSQL 14, when fmgroids.h gained overload-disambiguated names for aggregates; before that, aggregates had no fmgroids.h entry at all. Same stable OID.

Definition at line 117 of file compatibility.h.

◆ F_COUNT_

#define F_COUNT_   2803

OID of count() aggregate function (pre-PG 14).

Definition at line 90 of file compatibility.h.

◆ F_COUNT_ANY

#define F_COUNT_ANY   2147

OID of count(*) / count(any) aggregate function (pre-PG 14).

Definition at line 88 of file compatibility.h.

◆ F_SUM_INT4

#define F_SUM_INT4   2108

OID of sum(int4) aggregate function (pre-PG 14).

Definition at line 92 of file compatibility.h.

◆ TYPALIGN_CHAR

#define TYPALIGN_CHAR   'c'

Definition at line 108 of file compatibility.h.

◆ TYPALIGN_INT

#define TYPALIGN_INT   'i'

Alignment codes for the array routines (construct_array / deconstruct_array).

The TYPALIGN_* macros (in catalog/pg_type.h) were introduced in PostgreSQL 13; on PG 10-12 the alignment is passed as the older 'i' / 'c' characters.

Definition at line 107 of file compatibility.h.

Function Documentation

◆ list_insert_nth()

List * list_insert_nth ( List * list,
int pos,
void * datum )

Insert datum at position pos in list (PG < 13 backport).

PostgreSQL 13 introduced list_insert_nth() when lists were reimplemented as arrays. This declaration provides the same function for older PostgreSQL versions; the implementation lives in compatibility.c.

Parameters
listThe list to insert into (may be NIL).
posZero-based index at which to insert the new element.
datumThe value to insert.
Returns
The (possibly reallocated) list.

Definition at line 15 of file compatibility.c.

Here is the caller graph for this function:

◆ my_list_delete_cell()

List * my_list_delete_cell ( List * list,
ListCell * cell,
ListCell * prev )
inlinestatic

Version-agnostic wrapper around list_delete_cell().

PostgreSQL 13 changed list_delete_cell() to no longer require the previous cell pointer (because lists became arrays). This inline helper selects the correct call form at compile time.

Parameters
listThe list to modify.
cellThe cell to delete.
prevThe cell immediately before cell (ignored on PG ≥ 13).
Returns
The modified list.

Definition at line 41 of file compatibility.h.

Here is the caller graph for this function:

◆ my_lnext()

ListCell * my_lnext ( const List * l,
const ListCell * c )
inlinestatic

Version-agnostic wrapper around lnext().

PostgreSQL 13 added the list pointer parameter to lnext() to support the array-based list implementation. This inline helper selects the correct call form at compile time.

Parameters
lThe list (ignored on PG < 13).
cThe current cell.
Returns
The next cell, or NULL if c is the last element.

Definition at line 60 of file compatibility.h.

Here is the caller graph for this function: