Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples for Customized options #128

Open
W1M0R opened this issue Apr 26, 2021 · 3 comments
Open

Examples for Customized options #128

W1M0R opened this issue Apr 26, 2021 · 3 comments
Labels
good first issue Good for newcomers

Comments

@W1M0R
Copy link

W1M0R commented Apr 26, 2021

Postgres has support for extension variables:

This feature was designed to allow parameters not normally known to PostgreSQL to be added by add-on modules (such as procedural languages). This allows extension modules to be configured in the standard ways.

Custom options have two-part names: an extension name, then a dot, then the parameter name proper, much like qualified names in SQL. An example is plpgsql.variable_conflict.

Because custom options may need to be set in processes that have not loaded the relevant extension module, PostgreSQL will accept a setting for any two-part parameter name. Such variables are treated as placeholders and have no function until the module that defines them is loaded. When an extension module is loaded, it will add its variable definitions, convert any placeholder values according to those definitions, and issue warnings for any unrecognized placeholders that begin with its extension name.

Does pgx provide a way to add/register variables for an extension?

@eeeebbbbrrrr
Copy link
Contributor

Hi there! pgx sure does. It provides a few safe wrappers into Postgres' GUC (grand unified configuraiton) system. Sadly, pgx' docs for this aren't great right now, but there's a fairly complete (and working!) example of all this in ZomboDB: https://github.com/zombodb/zombodb/blob/master/src/gucs/mod.rs

You'll need to register your GUC variables via the _PG_init() function, which you can see ZomboDB does here: https://github.com/zombodb/zombodb/blob/7d0635a6b1a857c937f871102d53bb688a7916ab/src/lib.rs#L29

I'd like to put together some examples for this in pgx' repo someday. It's a pretty nice feature.

@eeeebbbbrrrr eeeebbbbrrrr added the question Further information is requested label Apr 26, 2021
@W1M0R
Copy link
Author

W1M0R commented Apr 26, 2021

Awesome @eeeebbbbrrrr! Thank you for your efforts to contribute such a helpful library/tool to the postgres ecosystem.

@Hoverbear Hoverbear changed the title Customized options Examples for Customized options Sep 3, 2021
@Hoverbear
Copy link
Contributor

I updated the issue title to reflect that this is an existing feature and the desire is for an example demonstrating the feature!

@Hoverbear Hoverbear added good first issue Good for newcomers and removed question Further information is requested labels Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants