-- FUNCTION: aws_commons.fstripcharacters(character varying, character varying)

-- DROP FUNCTION IF EXISTS aws_commons.fstripcharacters(character varying, character varying);

CREATE OR REPLACE FUNCTION aws_commons.fstripcharacters(
	par_value character varying,
	par_remove character varying)
    RETURNS character varying
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE PARALLEL UNSAFE
AS $BODY$
DECLARE
		var_i INTEGER;
		var_len INTEGER;
		var_c char(1);
BEGIN 
	IF par_value IS NULL OR par_remove IS NULL OR par_remove = '' 
	THEN 
		RETURN par_value;
	ELSE
		var_i = 1;
		var_len = length(par_remove);
		WHILE var_i <= var_len LOOP			
			var_c = substring(par_remove,var_i,1);
			par_value = REPLACE(par_value, var_c, '');
			var_i = var_i + 1;
		END LOOP;
		
		RETURN par_value;
	END IF;
END;
$BODY$;

ALTER FUNCTION aws_commons.fstripcharacters(character varying, character varying)
    OWNER TO postgres;
