-
-
Save slattery/ea3313d9516238c11526 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION cut_nicely(my_string VARCHAR, my_length INTEGER) RETURNS varchar AS $$ | |
DECLARE | |
my_pointer INTEGER; | |
BEGIN | |
my_pointer := my_length; | |
WHILE my_pointer < length(my_string) AND transliterate(substr(my_string, my_pointer, 1)) ~* '[a-z]' LOOP | |
my_pointer := my_pointer + 1; | |
END LOOP; | |
RETURN substr(my_string, 1, my_pointer); | |
END; | |
$$ LANGUAGE plpgsql | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment