diff --git a/sql/object_reference--0.2.0.sql b/sql/object_reference--0.2.0.sql index eaab900..d522812 100644 --- a/sql/object_reference--0.2.0.sql +++ b/sql/object_reference--0.2.0.sql @@ -1,5 +1,37 @@ /* DO NOT EDIT - AUTO-GENERATED FILE */ -SET LOCAL client_min_messages = WARNING; +/* + * Quiet the NOTICEs this install script emits (e.g. duplicate CREATE ROLE) + * without overriding a caller who has deliberately asked for even less output. + * + * CREATE EXTENSION runs the whole script in one transaction, so a blind + * `SET LOCAL client_min_messages = WARNING` clobbers the caller's setting for + * the entire statement -- including any CASCADE that pulls this extension in + * as a dependency (see issue #4). A caller who set a stricter level such as + * ERROR to keep install output quiet would be silently overridden. + * + * Instead only raise the floor to WARNING; never lower it below the level the + * caller chose. SET LOCAL inside a DO block still applies to the rest of the + * (CREATE EXTENSION) transaction, and reverts at commit so it does not leak + * into the caller's session. + */ +DO $$ +DECLARE + -- client_min_messages levels ordered least-to-most severe (LOG sorts + -- between DEBUG1 and NOTICE for this GUC). + c_levels CONSTANT text[] := ARRAY[ + 'debug5', 'debug4', 'debug3', 'debug2', 'debug1' + , 'log', 'notice', 'warning', 'error' + ]; +BEGIN + IF pg_catalog.array_position( + c_levels + , pg_catalog.lower(pg_catalog.current_setting('client_min_messages')) + ) < pg_catalog.array_position(c_levels, 'warning') + THEN + SET LOCAL client_min_messages = warning; + END IF; +END +$$; \echo This extension must be loaded via 'CREATE EXTENSION object_reference;' \echo You really, REALLY do NOT want to try and load this via psql!!! \echo It will FAIL during pg_dump! \quit diff --git a/sql/object_reference.sql b/sql/object_reference.sql index 6aeb197..6391955 100644 --- a/sql/object_reference.sql +++ b/sql/object_reference.sql @@ -1,4 +1,36 @@ -SET LOCAL client_min_messages = WARNING; +/* + * Quiet the NOTICEs this install script emits (e.g. duplicate CREATE ROLE) + * without overriding a caller who has deliberately asked for even less output. + * + * CREATE EXTENSION runs the whole script in one transaction, so a blind + * `SET LOCAL client_min_messages = WARNING` clobbers the caller's setting for + * the entire statement -- including any CASCADE that pulls this extension in + * as a dependency (see issue #4). A caller who set a stricter level such as + * ERROR to keep install output quiet would be silently overridden. + * + * Instead only raise the floor to WARNING; never lower it below the level the + * caller chose. SET LOCAL inside a DO block still applies to the rest of the + * (CREATE EXTENSION) transaction, and reverts at commit so it does not leak + * into the caller's session. + */ +DO $$ +DECLARE + -- client_min_messages levels ordered least-to-most severe (LOG sorts + -- between DEBUG1 and NOTICE for this GUC). + c_levels CONSTANT text[] := ARRAY[ + 'debug5', 'debug4', 'debug3', 'debug2', 'debug1' + , 'log', 'notice', 'warning', 'error' + ]; +BEGIN + IF pg_catalog.array_position( + c_levels + , pg_catalog.lower(pg_catalog.current_setting('client_min_messages')) + ) < pg_catalog.array_position(c_levels, 'warning') + THEN + SET LOCAL client_min_messages = warning; + END IF; +END +$$; \echo This extension must be loaded via 'CREATE EXTENSION object_reference;' \echo You really, REALLY do NOT want to try and load this via psql!!! \echo It will FAIL during pg_dump! \quit diff --git a/test/expected/zzz_build.out b/test/expected/zzz_build.out index ff07ade..6b55381 100644 --- a/test/expected/zzz_build.out +++ b/test/expected/zzz_build.out @@ -2,16 +2,16 @@ This extension must be loaded via CREATE EXTENSION object_reference; You really, REALLY do NOT want to try and load this via psql!!! -psql:test/temp_load.not_sql:159: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:191: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! -psql:test/temp_load.not_sql:160: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:192: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! -psql:test/temp_load.not_sql:414: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:446: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! @@ -21,9 +21,9 @@ psql:test/temp_load.not_sql:414: WARNING: I promise you will be sorry if you tr -psql:test/temp_load.not_sql:521: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:553: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! -psql:test/temp_load.not_sql:528: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:560: WARNING: I promise you will be sorry if you try to use this as anything other than an extension!