[PATCH] Add pg_get_event_trigger_ddl() function - Mailing list pgsql-hackers

From Ian Lawrence Barwick
Subject [PATCH] Add pg_get_event_trigger_ddl() function
Date
Msg-id CAB8KJ=jAGYFYU77r2YPKxe_0MYjt529X-bKskLznigQFCrGimQ@mail.gmail.com
Whole thread
Responses Re: [PATCH] Add pg_get_event_trigger_ddl() function
List pgsql-hackers
Hi

Attached is a patch implementing a function to generate the DDL for a CREATE
EVENT TRIGGER statement. This complements existing similar functions
(pg_get_database_ddl(), pg_get_role_ddl() etc.).

Patch includes regression test and documentation.

Example:

  CREATE OR REPLACE FUNCTION forbid_table_rewrites()
    RETURNS event_trigger
    LANGUAGE plpgsql
  AS $$
    BEGIN
      RAISE EXCEPTION 'command % prohibited', tg_tag;
    END;
   $$;

  CREATE EVENT TRIGGER forbid_rewrites
    ON table_rewrite
    WHEN tag IN ('ALTER TABLE', 'ALTER MATERIALIZED VIEW')
      EXECUTE FUNCTION forbid_table_rewrites();

SELECT pg_get_event_trigger_ddl('forbid_rewrites');

postgres=# SELECT pg_get_event_trigger_ddl('forbid_rewrites',true);
                  pg_get_event_trigger_ddl
------------------------------------------------------------
 CREATE EVENT TRIGGER forbid_rewrites                      +
     ON table_rewrite                                      +
     WHEN TAG IN ('ALTER TABLE', 'ALTER MATERIALIZED VIEW')+
     EXECUTE FUNCTION public.forbid_table_rewrites();
(1 row)


Regards

Ian Barwick

Attachment

pgsql-hackers by date:

Previous
From: wenhui qiu
Date:
Subject: Re: [PATCH] Refactor SLRU to always use long file names
Next
From: Peter Smith
Date:
Subject: A new C function `get_partition_root`.