From 2225cba3070cef459e023e10efb008f51c80b573 Mon Sep 17 00:00:00 2001 From: Christophe Eymard Date: Thu, 28 Nov 2024 09:54:18 +0100 Subject: [PATCH 1/3] Add an example for PGRST_APP_SETTINGS_* I had to figure stuff out and I thought it would be useful for everyone if I provided some more information --- docs/references/configuration.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/references/configuration.rst b/docs/references/configuration.rst index 5159283ac3..9f5d3f16a3 100644 --- a/docs/references/configuration.rst +++ b/docs/references/configuration.rst @@ -191,6 +191,10 @@ app.settings.* Arbitrary settings that can be used to pass in secret keys directly as strings, or via OS environment variables. For instance: :code:`app.settings.jwt_secret = "$(MYAPP_JWT_SECRET)"` will take :code:`MYAPP_JWT_SECRET` from the environment and make it available to PostgreSQL functions as :code:`current_setting('app.settings.jwt_secret')`. + When using the environment variable `PGRST_APP_SETTINGS_*` form, the remainder of the variable is used as the new name. Case is not important : :code:`PGRST_APP_SETTINGS_MY_ENV_VARIABLE=some_value` can be accessed in postgres as :code:`current_setting('app.settings.my_env_variable')`. + + The :code:`current_setting` function has `an optional boolean second `_ argument to avoid it from raising an error if the value was not defined. Default values to :code:`app.settings` can then easily be given by combining this argument with :code:`coalesce` : :code:`coalesce(current_setting('app.settings.my_custom_variable', true), 'default value')` + .. _db-aggregates-enabled: db-aggregates-enabled From 50b5b6a2c523ffa33a29df465d43057225b251c9 Mon Sep 17 00:00:00 2001 From: Christophe Eymard Date: Thu, 28 Nov 2024 19:58:15 +0100 Subject: [PATCH 2/3] docs: added nullif use in current_setting default value use case --- docs/references/configuration.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/configuration.rst b/docs/references/configuration.rst index 9f5d3f16a3..413f8585c4 100644 --- a/docs/references/configuration.rst +++ b/docs/references/configuration.rst @@ -193,7 +193,7 @@ app.settings.* When using the environment variable `PGRST_APP_SETTINGS_*` form, the remainder of the variable is used as the new name. Case is not important : :code:`PGRST_APP_SETTINGS_MY_ENV_VARIABLE=some_value` can be accessed in postgres as :code:`current_setting('app.settings.my_env_variable')`. - The :code:`current_setting` function has `an optional boolean second `_ argument to avoid it from raising an error if the value was not defined. Default values to :code:`app.settings` can then easily be given by combining this argument with :code:`coalesce` : :code:`coalesce(current_setting('app.settings.my_custom_variable', true), 'default value')` + The :code:`current_setting` function has `an optional boolean second `_ argument to avoid it from raising an error if the value was not defined. Default values to :code:`app.settings` can then easily be given by combining this argument with :code:`coalesce` and :code:`nullif` : :code:`coalesce(nullif(current_setting('app.settings.my_custom_variable', true), ''), 'default value')`. The use of :code:`nullif` is necessary because if set in a transaction, the setting is sometimes not "rolled back" to :code:`null`. See also :ref:`this section ` for more information on this behaviour. .. _db-aggregates-enabled: From 3b70ea706c3ee966cd214804732203e4ed431652 Mon Sep 17 00:00:00 2001 From: Christophe Eymard Date: Fri, 29 Nov 2024 08:14:59 +0100 Subject: [PATCH 3/3] removed "easily" --- docs/references/configuration.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/configuration.rst b/docs/references/configuration.rst index 413f8585c4..4237d55bcc 100644 --- a/docs/references/configuration.rst +++ b/docs/references/configuration.rst @@ -193,7 +193,7 @@ app.settings.* When using the environment variable `PGRST_APP_SETTINGS_*` form, the remainder of the variable is used as the new name. Case is not important : :code:`PGRST_APP_SETTINGS_MY_ENV_VARIABLE=some_value` can be accessed in postgres as :code:`current_setting('app.settings.my_env_variable')`. - The :code:`current_setting` function has `an optional boolean second `_ argument to avoid it from raising an error if the value was not defined. Default values to :code:`app.settings` can then easily be given by combining this argument with :code:`coalesce` and :code:`nullif` : :code:`coalesce(nullif(current_setting('app.settings.my_custom_variable', true), ''), 'default value')`. The use of :code:`nullif` is necessary because if set in a transaction, the setting is sometimes not "rolled back" to :code:`null`. See also :ref:`this section ` for more information on this behaviour. + The :code:`current_setting` function has `an optional boolean second `_ argument to avoid it from raising an error if the value was not defined. Default values to :code:`app.settings` can then be given by combining this argument with :code:`coalesce` and :code:`nullif` : :code:`coalesce(nullif(current_setting('app.settings.my_custom_variable', true), ''), 'default value')`. The use of :code:`nullif` is necessary because if set in a transaction, the setting is sometimes not "rolled back" to :code:`null`. See also :ref:`this section ` for more information on this behaviour. .. _db-aggregates-enabled: