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 "catalog/namespace.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().
static FuncCandidateList FuncnameGetCandidatesCompat (List *names, int nargs, List *argnames, bool expand_variadic, bool expand_defaults, bool include_out_arguments, bool missing_ok)
 Version-agnostic wrapper around FuncnameGetCandidates().
static FuncCandidateList OpernameGetCandidatesCompat (List *names, char oprkind, bool missing_schema_ok)
 Version-agnostic wrapper around OpernameGetCandidates().
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().
  • FuncnameGetCandidates() / OpernameGetCandidates() (14, 19): PostgreSQL 14 added an include_out_arguments parameter to the former; PostgreSQL 19 added a mandatory fgc_flags out-parameter to both. The *Compat wrappers take the PG 14-style argument list and drop / dummy-fill the extra arguments as needed.

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

◆ F_COUNT_

#define F_COUNT_   2803

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

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

◆ F_SUM_INT4

#define F_SUM_INT4   2108

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

Definition at line 145 of file compatibility.h.

◆ TYPALIGN_CHAR

#define TYPALIGN_CHAR   'c'

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

Function Documentation

◆ FuncnameGetCandidatesCompat()

FuncCandidateList FuncnameGetCandidatesCompat ( List * names,
int nargs,
List * argnames,
bool expand_variadic,
bool expand_defaults,
bool include_out_arguments,
bool missing_ok )
inlinestatic

Version-agnostic wrapper around FuncnameGetCandidates().

Takes the PostgreSQL 14+ argument list. On PG < 14 the include_out_arguments parameter (added in 14) is dropped; on PG >= 19 the fgc_flags out-parameter (added in 19, must not be NULL) receives a discarded local, as no caller inspects the lookup-failure flags.

Definition at line 85 of file compatibility.h.

Here is the caller graph for this function:

◆ 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 47 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 66 of file compatibility.h.

Here is the caller graph for this function:

◆ OpernameGetCandidatesCompat()

FuncCandidateList OpernameGetCandidatesCompat ( List * names,
char oprkind,
bool missing_schema_ok )
inlinestatic

Version-agnostic wrapper around OpernameGetCandidates().

PostgreSQL 19 added an fgc_flags out-parameter (must not be NULL); it receives a discarded local, as no caller inspects the lookup-failure flags.

Definition at line 112 of file compatibility.h.

Here is the caller graph for this function: