sql-formatter-org / sql-formatter

A whitespace formatter for different query languages
https://sql-formatter-org.github.io/sql-formatter/
MIT License
2.37k stars 405 forks source link

[FORMATTING] Error when formatting Clickhouse SQL with Array column type #752

Closed eryx closed 5 months ago

eryx commented 5 months ago

Input data

Table Schema:

database: clickhouse

schema:

CREATE TABLE test_table_name (
  id String,
  array_column Array(String),
)
ENGINE = MergeTree()
PRIMARY KEY (id);

sql:

INSERT INTO test_table_name (id, array_column) VALUES ('unique-id', ['abc', 'def'])

Expected Output

guest@localhost% sql-formatter test.sql -o test.fmt.sql
/opt/homebrew/lib/node_modules/sql-formatter/dist/index.cjs:15909
    return new Error(
           ^

Error: Parse error: Unexpected "['abc', 'd" at line 1 column 69.
This likely happens because you're using the default "sql" dialect.
If possible, please select a more specific dialect (like sqlite, postgresql, etc).
    at TokenizerEngine.createParseError (/opt/homebrew/lib/node_modules/sql-formatter/dist/index.cjs:15909:12)
    at TokenizerEngine.tokenize (/opt/homebrew/lib/node_modules/sql-formatter/dist/index.cjs:15899:22)
    at Tokenizer.tokenize (/opt/homebrew/lib/node_modules/sql-formatter/dist/index.cjs:16019:65)
    at LexerAdapter.tokenize (/opt/homebrew/lib/node_modules/sql-formatter/dist/index.cjs:16856:37)
    at LexerAdapter.reset (/opt/homebrew/lib/node_modules/sql-formatter/dist/index.cjs:16391:24)
    at Parser.feed (/opt/homebrew/lib/node_modules/sql-formatter/node_modules/nearley/lib/nearley.js:281:15)
    at Object.parse (/opt/homebrew/lib/node_modules/sql-formatter/dist/index.cjs:16863:34)
    at Formatter.parse (/opt/homebrew/lib/node_modules/sql-formatter/dist/index.cjs:17572:49)
    at Formatter.format (/opt/homebrew/lib/node_modules/sql-formatter/dist/index.cjs:17567:22)
    at formatDialect (/opt/homebrew/lib/node_modules/sql-formatter/dist/index.cjs:17679:57)

Node.js v21.7.1

sql-formatter version 15.3.2

nene commented 5 months ago

Well, that's to be expected as Clickhouse SQL dialect is not supported by the formatter. See list of supported dialects

Related to: #614