v.20.5Improvement

Enhanced Parsing of C-style Backslash Escapes for Better LIKE and Regular Expression Compatibility in ClickHouse

When parsing C-style backslash escapes in string literals, VALUES and various text formats (this is an extension to SQL standard that is endemic for ClickHouse and MySQL), keep backslash if unknown escape sequence is found (e.g. % or \w) that will make usage of LIKE and match regular expressions more convenient (it's enough to write name LIKE 'used_cars' instead of name LIKE 'used\_cars') and more compatible at the same time. This fixes #10922. #11208 (alexey-milovidov).
Improved handling of C-style backslash escapes in string literals, VALUES, and various text formats by preserving unknown escape sequences when parsing. This enhancement facilitates more convenient and compatible use of LIKE and match regular expressions in ClickHouse.

Why it matters

This feature addresses the problem of cumbersome escaping in string patterns involving backslashes, especially when using LIKE and regex matches. By keeping unknown escape sequences intact (e.g., % or \w), it reduces the need for double escaping and improves compatibility with MySQL and user expectations, simplifying pattern writing.

How to use it

No explicit configuration is needed. The updated parser automatically retains unknown backslash escapes in string literals, VALUES, and applicable text formats, allowing users to write patterns like:

SELECT * FROM table WHERE name LIKE 'used_cars'


instead of double escaping the underscore.