Jorge Arévalo
Jorge Arévalo

Reputation: 2998

PostgreSQL: Evaluating SQL expression from C-functions

I need to write a C-function to extend my PostgreSQL server functionality. One of the arguments of that function is a string representing any PostgreSQL valid expression returning a number. For example:

and so on

The point is my function first replaces some values in the expression (variable names) for numbers and then it should execute the expression and returns the result (a number). With PL/pgSQL I can use EXECUTE expr INTO val, but how could I do it in a C function?

Many thanks in advance, and best regards

Upvotes: 1

Views: 354

Answers (1)

Milen A. Radev
Milen A. Radev

Reputation: 62583

SPI_execute_with_args sounds closer to what are you looking for. Check out the examples too.

Upvotes: 1

Related Questions