select create_newtype_text('public.grp_tag'); create table public.grp ( id int not null primary key generated always as identity , uid uuid not null default gen_random_uuid() , deleted boolean not null default false , tag public.grp_tag not null unique ); insert into public.grp (tag) values (grp_tag_of_string('admins')); create function public.do_grp_add_admins() returns trigger volatile language plpgsql as $$ declare admins int[]; begin select array_agg(usr.id) from public.grp_members_admins() as usr into admins; perform public.grp_add_members( to_grp => NEW.id , add_usrs => admins ); return null; end; $$; create trigger grp_add_admins after insert on public.grp for each row execute function public.do_grp_add_admins(); select audit( 'public' , 'grp' , array[] :: audited_column[] , soft_delete => true ); select immutable( 'public' , 'grp' , array[ 'id' , 'uid' , 'tag' ] );