From: | kaido vaikla <kaido(dot)vaikla(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-admin(at)postgresql(dot)org |
Subject: | Re: event_trigger, 'DROP SCHEMA' |
Date: | 2024-07-26 18:12:44 |
Message-ID: | CA+427g_x5RA8L3eCFJBsX4NFprXvvdjYLYFothbaCw7tBP=gVw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
ty tom, works now
kvpg2=# cREATE or replace FUNCTION trigger_after_drop_schema() RETURNS
event_trigger
LANGUAGE plpgsql AS $$
DECLARE
r RECORD;
BEGIN
FOR r IN SELECT * FROM pg_event_trigger_dropped_objects()
LOOP
IF r.object_type = 'schema' THEN
execute format ('drop role IF EXISTS r_%I', r.object_name);
end if;
END LOOP;
END;
$$;
CREATE FUNCTION
kvpg2=# drop schema test;
DROP SCHEMA
kvpg2=# \du r_test
List of roles
Role name | Attributes
-----------+------------
br
Kaido
On Fri, 26 Jul 2024 at 20:44, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> kaido vaikla <kaido(dot)vaikla(at)gmail(dot)com> writes:
> > FOR r IN SELECT * FROM pg_event_trigger_dropped_objects()
> > LOOP
> > execute format ('drop role IF EXISTS r_%I', r.object_name);
> > END LOOP;
>
> > kvpg2=# drop schema test;
> > ERROR: null values cannot be formatted as an SQL identifier
> > CONTEXT: PL/pgSQL function trigger_after_drop_schema() line 7 at EXECUTE
>
> > Question, what i do wrong?
>
> Assume that every dropped object has a name, looks like.
> You would probably do well to check object_type before
> trying to drop the role.
>
> regards, tom lane
>
From | Date | Subject | |
---|---|---|---|
Next Message | Wells Oliver | 2024-07-27 00:57:51 | Faster pg_resore with autovacuum off? |
Previous Message | Tom Lane | 2024-07-26 17:44:01 | Re: event_trigger, 'DROP SCHEMA' |