remove_extra_spaces(string)
Removes extra spaces (tab, space, newline, paragraph, etc.) in a <string>.
CREATE OR REPLACE FUNCTION `justfunctions.eu.remove_extra_spaces`(`string` string)
RETURNS string AS (TRIM(REGEXP_REPLACE(REGEXP_REPLACE(string,r'\n+|\t+|\r+|\\n+|\\t+|\\r+|\\s+',''), r'\s+', ' ')))
OPTIONS ( description = '''Removes extra spaces (tab, space, newline, paragraph, etc.) in a <string>.''')
Example
SELECT `justfunctions.eu.remove_extra_spaces`("\tHi there
.\n\n")
Hi there.