Last active
February 5, 2022 19:58
-
-
Save psujit775/d6d24010d58bca11d5e51d1c038afc39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION public.audit_ddl() | |
RETURNS event_trigger | |
LANGUAGE plpgsql | |
AS $function$ | |
declare _qry text; | |
BEGIN | |
if (tg_tag='CREATE TABLE' or tg_tag='ALTER TABLE' or tg_tag='DROP TABLE') then | |
SELECT current_query() into _qry; | |
insert into public.ddl_audit | |
values | |
( | |
default,current_timestamp,current_user,cast(TXID_CURRENT()as varchar(16)),tg_tag,0,'',current_schema,_qry | |
); | |
end if; | |
END; | |
$function$ | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment