When concatenating literal values with a newline separator in group_concat, always escape existing backslashes and replace CR/LF sequences in the individual values first: replace(replace(?val, "\\\\", "\\\\\\\\"), "[\r\n]+", "\\\\n"). First escape existing backslashes (\\ → \\\\), then replace any sequence of CR/LF characters with the two-character escape \\n. This ensures values containing these characters can be safely split on newlines later.