Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions sql/extension_drop--1.0.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,33 @@
*/
CREATE SCHEMA __extension_drop;

CREATE TABLE __extension_drop.messages AS SELECT pg_catalog.current_setting('client_min_messages');
SET client_min_messages = WARNING;
/*
* Only raise client_min_messages to WARNING to quiet install-time NOTICEs;
* never lower it below the level the caller chose. CREATE EXTENSION runs the
* whole script in one transaction, so a blind SET here would clobber a caller
* who deliberately set a stricter level (e.g. ERROR) for the entire statement,
* including any CASCADE. SET LOCAL inside a DO block still applies for the rest
* of the transaction and reverts at commit, so the caller's session is left
* untouched (no explicit save/restore needed).
*/
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
$$;

CREATE FUNCTION __extension_drop.exec(
sql text
Expand Down Expand Up @@ -302,10 +327,6 @@ CREATE EVENT TRIGGER extension_drop
/*
* Drop "temporary" objects
*/
SELECT __extension_drop.exec('SET client_min_messages = ' || current_setting)
FROM __extension_drop.messages
;
DROP TABLE __extension_drop.messages;
DROP FUNCTION __extension_drop.create_function(
function_name text
, args text
Expand Down
33 changes: 27 additions & 6 deletions sql/extension_drop.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,33 @@
*/
CREATE SCHEMA __extension_drop;

CREATE TABLE __extension_drop.messages AS SELECT pg_catalog.current_setting('client_min_messages');
SET client_min_messages = WARNING;
/*
* Only raise client_min_messages to WARNING to quiet install-time NOTICEs;
* never lower it below the level the caller chose. CREATE EXTENSION runs the
* whole script in one transaction, so a blind SET here would clobber a caller
* who deliberately set a stricter level (e.g. ERROR) for the entire statement,
* including any CASCADE. SET LOCAL inside a DO block still applies for the rest
* of the transaction and reverts at commit, so the caller's session is left
* untouched (no explicit save/restore needed).
*/
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
$$;

CREATE FUNCTION __extension_drop.exec(
sql text
Expand Down Expand Up @@ -301,10 +326,6 @@ CREATE EVENT TRIGGER extension_drop
/*
* Drop "temporary" objects
*/
SELECT __extension_drop.exec('SET client_min_messages = ' || current_setting)
FROM __extension_drop.messages
;
DROP TABLE __extension_drop.messages;
DROP FUNCTION __extension_drop.create_function(
function_name text
, args text
Expand Down
Loading