1

I'm writing a C user defined extension function for Postgres and would like to get the value of parameter that I set in SQL level in my C code.

For example, in SQL, I have something like:

CREATE FUNCTION my_test_function(text) RETURNS text AS 'path_to_so', 'my_function' LANGUAGE C STRICT SET some_boolean TO true;

The question is how can I get the value of some_boolean variable in my C code?

Datum my_test_function(PG_FUNCTION_ARGS) {
// try to get some_boolean here
}

1 Answer 1

1

some_boolean must be an existing GUC (configuration parameter), else the function definition will produce

ERROR:  unrecognized configuration parameter "some_boolean"

If it is a GUC, it is either a core PostgreSQL GUG, or it was registered somewhere with DefineCustomBoolVariable (from utils/guc.h).

Each GUC belongs to a C variable, commonly a global one.

Use that variable in your code!

Sign up to request clarification or add additional context in comments.

1 Comment

Thank @Laurenz Albe. It's registered in _PG_init function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.