Skip to content

Instantly share code, notes, and snippets.

@psujit775
Last active February 5, 2022 19:58
Show Gist options
  • Save psujit775/d6d24010d58bca11d5e51d1c038afc39 to your computer and use it in GitHub Desktop.
Save psujit775/d6d24010d58bca11d5e51d1c038afc39 to your computer and use it in GitHub Desktop.
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