Search code examples
postgresqlpostgresql-13

How to perform a select statement from inside a c-extension


I managed to get a c-extension to compile and run with the help of the official documentation https://www.postgresql.org/docs/13/xfunc-c.html.

Now I don't see in the examples provided a way to perform a select inside of a c-extension. Generally I don't know where to look for documentatin of how to perform any "normal" sql-statements inside a c-extension.


Solution

  • I think are looking for the sibling chapter on the Server Programming Interface. Contrib contains a whole directory of example code for using SPI, called 'contrib/spi'. There are many other modules in contrib that also use SPI as a component of their operations.