formatQuery: improve doc

This commit is contained in:
Salvatore Mesoraca 2023-10-26 13:08:11 +02:00
parent 0bda99e880
commit 21e0c510c8
No known key found for this signature in database
GPG Key ID: 0567E50A25403074
2 changed files with 4 additions and 56 deletions

View File

@ -2797,7 +2797,7 @@ message Root
## formatQuery ## formatQuery
Returns a formatted version of the given SQL query. Returns a formatted, possibly multi-line, version of the given SQL query.
**Syntax** **Syntax**
@ -2815,30 +2815,6 @@ formatQuery(query)
**Example** **Example**
```sql
SELECT formatQuery('select 1;');
```
Result:
```result
┌─formatQuery('select 1;')─┐
│ SELECT 1 │
└──────────────────────────┘
```
```sql
SELECT formatQuery('SeLecT 1');
```
Result:
```result
┌─formatQuery('SeLecT 1')──┐
│ SELECT 1 │
└──────────────────────────┘
```
```sql ```sql
SELECT formatQuery('select a, b FRom tab WHERE a > 3 and b < 3'); SELECT formatQuery('select a, b FRom tab WHERE a > 3 and b < 3');
``` ```
@ -2857,7 +2833,7 @@ WHERE (a > 3) AND (b < 3) │
## formatQueryOneLine ## formatQueryOneLine
Returns a formatted version of the given SQL query on a single line. Like formatQuery() but the returned formatted string contains no line breaks.
**Syntax** **Syntax**
@ -2881,30 +2857,6 @@ SELECT formatQueryOneLine('select 1;');
Result: Result:
```result
┌─formatQueryOneLine('select 1;')─┐
│ SELECT 1 │
└─────────────────────────────────┘
```
```sql
SELECT formatQueryOneLine('SeLecT 1');
```
Result:
```result
┌─formatQueryOneLine('SeLecT 1')──┐
│ SELECT 1 │
└─────────────────────────────────┘
```
```sql
SELECT formatQueryOneLine('select a, b FRom tab WHERE a > 3 and b < 3');
```
Result:
```result ```result
┌─formatQueryOneLine('select a, b FRom tab WHERE a > 3 and b < 3') ┌─formatQueryOneLine('select a, b FRom tab WHERE a > 3 and b < 3')
│ SELECT a, b FROM tab WHERE (a > 3) AND (b < 3) │ SELECT a, b FROM tab WHERE (a > 3) AND (b < 3)

View File

@ -106,13 +106,11 @@ struct NameFormatQueryOneLine
REGISTER_FUNCTION(formatQuery) REGISTER_FUNCTION(formatQuery)
{ {
factory.registerFunction<FunctionFormatQuery<false, NameFormatQuery>>(FunctionDocumentation{ factory.registerFunction<FunctionFormatQuery<false, NameFormatQuery>>(FunctionDocumentation{
.description = "Returns a formatted version of the given SQL query.\n[example:simple]\n[example:camelcase]", .description = "Returns a formatted, possibly multi-line, version of the given SQL query.\n[example:multiline]",
.syntax = "formatQuery(query)", .syntax = "formatQuery(query)",
.arguments = {{"query", "The SQL query to be formatted. [String](../../sql-reference/data-types/string.md)"}}, .arguments = {{"query", "The SQL query to be formatted. [String](../../sql-reference/data-types/string.md)"}},
.returned_value = "The formatted query. [String](../../sql-reference/data-types/string.md).", .returned_value = "The formatted query. [String](../../sql-reference/data-types/string.md).",
.examples{ .examples{
{"simple", "SELECT formatQuery('select 1;')", "SELECT 1"},
{"camelcase", "SELECT formatQuery('SeLecT 1')", "SELECT 1"},
{"multiline", {"multiline",
"SELECT formatQuery('select a, b FRom tab WHERE a > 3 and b < 3');", "SELECT formatQuery('select a, b FRom tab WHERE a > 3 and b < 3');",
"SELECT\n" "SELECT\n"
@ -126,13 +124,11 @@ REGISTER_FUNCTION(formatQuery)
REGISTER_FUNCTION(formatQueryOneLine) REGISTER_FUNCTION(formatQueryOneLine)
{ {
factory.registerFunction<FunctionFormatQuery<true, NameFormatQueryOneLine>>(FunctionDocumentation{ factory.registerFunction<FunctionFormatQuery<true, NameFormatQueryOneLine>>(FunctionDocumentation{
.description = "Returns a formatted version of the given SQL query on a single line.\n[example:simple]\n[example:camelcase]", .description = "Like formatQuery() but the returned formatted string contains no line breaks.\n[example:multiline]",
.syntax = "formatQueryOneLine(query)", .syntax = "formatQueryOneLine(query)",
.arguments = {{"query", "The SQL query to be formatted. [String](../../sql-reference/data-types/string.md)"}}, .arguments = {{"query", "The SQL query to be formatted. [String](../../sql-reference/data-types/string.md)"}},
.returned_value = "The formatted query. [String](../../sql-reference/data-types/string.md).", .returned_value = "The formatted query. [String](../../sql-reference/data-types/string.md).",
.examples{ .examples{
{"simple", "SELECT formatQueryOneLine('select 1;')", "SELECT 1"},
{"camelcase", "SELECT formatQueryOneLine('SeLecT 1')", "SELECT 1"},
{"multiline", {"multiline",
"SELECT formatQuery('select a, b FRom tab WHERE a > 3 and b < 3');", "SELECT formatQuery('select a, b FRom tab WHERE a > 3 and b < 3');",
"SELECT a, b FROM tab WHERE (a > 3) AND (b < 3)"}}, "SELECT a, b FROM tab WHERE (a > 3) AND (b < 3)"}},