-- drop function if exists public.mascara_cpf_lgpd(TEXT)CREATEORREPLACEFUNCTIONpublic.mascara_cpf_lgpd(in_cpfTEXT)RETURNSTEXTAS$$DECLAREclean_cpfTEXT;resultTEXT;BEGINclean_cpf:=regexp_replace(in_cpf,'[^0-9]','','g');IFchar_length(clean_cpf)<>11THENRAISEEXCEPTION'CPF inválido. Deve conter 11 dígitos.';ENDIF;result:=substring(clean_cpfFROM1FOR3)||'.XXX.XXX-'||substring(clean_cpfFROM10FOR2);RETURNresult;END;$$LANGUAGEplpgsql;