I’m working on a PostgreSQL extension (Apache AGE) and need to execute a SQL command from within a C-language function. How can I achieve this?
For context, I’m developing an extension that modifies some tables in a database, and I need to run some ALTER TABLE commands to add or remove columns, rename columns, or change column types, depending on certain conditions. I already have a C function that performs the necessary computations, but I don’t know how to execute a SQL command from within it.
Here’s a simplified version of my code:
PG_FUNCTION_INFO_V1(my_function);
Datum
my_function(PG_FUNCTION_ARGS)
{
// Perform some computations...
// Execute a SQL command (not sure how to do this)...
PG_RETURN_NULL();
}
Can anyone show me how to execute a SQL command inside a C function in a PostgreSQL extension? Any help would be appreciated!