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).
 

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.

Definition in file compatibility.h.

Macro Definition Documentation

◆ F_COUNT_

#define F_COUNT_   2803

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

Definition at line 87 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 85 of file compatibility.h.

◆ F_SUM_INT4

#define F_SUM_INT4   2108

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

Definition at line 89 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()

static 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 38 of file compatibility.h.

Here is the caller graph for this function:

◆ my_lnext()

static 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 57 of file compatibility.h.

Here is the caller graph for this function: