CREATE OR REPLACE FUNCTION REPLACER_LENGTH(str varchar, indexfloat, lengthfloat) RETURNS string LANGUAGE JAVASCRIPTAS$$ var start= INDEX -1; var end= STR.length - (LENGTH -1);return STR.substring(start, end);$$;SELECT REPLACER_LENGTH('abcdef', 2, 3) AS SOMETEXT;