v.23.10New Feature

Added SQL Query Formatting Functions

Added function formatQuery which returns a formatted version (possibly spanning multiple lines) of a SQL query string. Also added function formatQuerySingleLine which does the same but the returned string will not contain linebreaks. #55239 (Salvatore Mesoraca).
Introduces two new functions, formatQuery and formatQuerySingleLine, that return formatted versions of SQL query strings, enhancing readability and consistency.

Why it matters

These functions solve the problem of unformatted or inconsistently formatted SQL queries by providing standardized formatting. formatQuery returns a nicely formatted query with line breaks for better readability, while formatQuerySingleLine returns a compact single-line formatted query. This helps users and tools to process, debug, or display queries more effectively.

How to use it

Use the functions by passing a SQL query string as an argument to either formatQuery for multi-line formatted output or formatQuerySingleLine for a single-line formatted string. For example:

SELECT formatQuery('SELECT * FROM table WHERE x=1');
SELECT formatQuerySingleLine('SELECT * FROM table WHERE x=1');