postgresql_16:6.1.10 C-Language Functions
PostgreSQL 16 > Server Programming > Extending SQL > C-Language Functions
User-defined functions can be written in C (or a language that can be made compatible with C, such as C++). Such functions are compiled into dynamically loadable objects (also called shared libraries) and are loaded by the server on demand. The dynamic loading feature is what distinguishes “C language” functions from “internal” functions — the actual coding conventions are essentially the same for both. (Hence, the standard internal function library is a rich source of coding examples for user-defined C functions.)
Currently only one calling convention is used for C functions (“version 1”). Support for that calling convention is indicated by writing a PG_FUNCTION_INFO_V1() macro call for the function, as illustrated below.
Subsections
- postgresql_16:6.1.10.1 Dynamic Loading
- postgresql_16:6.1.10.2 Base Types in C-Language Functions
- postgresql_16:6.1.10.3 Version 1 Calling Conventions
- postgresql_16:6.1.10.4 Writing Code
- postgresql_16:6.1.10.5 Compiling and Linking Dynamically-Loaded Functions
- postgresql_16:6.1.10.6 Composite-Type Arguments
- postgresql_16:6.1.10.7 Returning Rows (Composite Types)
- postgresql_16:6.1.10.8 Returning Sets
- postgresql_16:6.1.10.9 Polymorphic Arguments and Return Types
- postgresql_16:6.1.10.10 Shared Memory and LWLocks
- postgresql_16:6.1.10.11 Using C++ for Extensibility