sql-formatter-org / sql-formatter

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

SQLServer system table 'master..sysprocesses' cannot be parsed #700

Closed CJWbiu closed 10 months ago

CJWbiu commented 10 months ago

Input data

SELECT es.TOTAL_ELAPSED_TIME FROM master..sysprocesses as prs left outer join sys.dm_exec_sessions as es on prs.spid = es.session_id where spid = 62

Expected Output

SELECT es.total_elapsed_time
FROM   master..sysprocesses AS prs
       LEFT OUTER JOIN sys.dm_exec_sessions AS es
                    ON prs.spid = es.session_id
WHERE  spid = 62 

Actual Output

An Unexpected Error Occurred
Parse error at token: . at line 1 column 42 Unexpected DOT token: {"type":"DOT","raw":".","text":".","start":41}. Instead, I was expecting to see one of the following: A LINE_COMMENT token based on: comment → ● %LINE_COMMENT _$ebnf$1 → _$ebnf$1 ● comment _ → ● _$ebnf$1 property_access → atomic_expression _ %DOT ● _ property_access$subexpression$1 atomic_expression$subexpression$1 → ● property_access atomic_expression → ● atomic_expression$subexpression$1 asteriskless_andless_expression$subexpression$1 → ● atomic_expression asteriskless_andless_expression → ● asteriskless_andless_expression$subexpression$1 asteriskless_free_form_sql$subexpression$1 → ● asteriskless_andless_expression asteriskless_free_form_sql → ● asteriskless_free_form_sql$subexpression$1 free_form_sql$subexpression$1 → ● asteriskless_free_form_sql free_form_sql → ● free_form_sql$subexpression$1 other_clause$ebnf$1 → other_clause$ebnf$1 ● free_form_sql other_clause → %RESERVED_CLAUSE ● other_clause$ebnf$1 clause$subexpression$1 → ● other_clause clause → ● clause$subexpression$1 expressions_or_clauses$ebnf$2 → expressions_or_clauses$ebnf$2 ● clause expressions_or_clauses → expressions_or_clauses$ebnf$1 ● expressions_or_clauses$ebnf$2 statement → ● expressions_or_clauses statement$subexpression$1 main$ebnf$1 → main$ebnf$1 ● statement main → ● main$ebnf$1 A BLOCK_COMMENT token based on: comment → ● %BLOCK_COMMENT _$ebnf$1 → _$ebnf$1 ● comment _ → ● _$ebnf$1 property_access → atomic_expression _ %DOT ● _
...

Usage

import { format } from 'sql-formatter';
format(text, { language: 'sql' })
nene commented 10 months ago

Thanks for reporting.

Can you point me to any resources that document this .. syntax in SQLServer?

I know of similar syntax in BigQuery, but there one can only use it inside quoted table names like `project..dataset....table` where the repeated . is simply treated the same as single .. Does the SQLServer also simply allow repeated .. instead of just ., or does the multi-dot syntax have some special meaning?

CJWbiu commented 10 months ago

Thanks for reporting.

Can you point me to any resources that document this .. syntax in SQLServer?

I know of similar syntax in BigQuery, but there one can only use it inside quoted table names like `project..dataset....table` where the repeated . is simply treated the same as single .. Does the SQLServer also simply allow repeated .. instead of just ., or does the multi-dot syntax have some special meaning?

master..sysprocesses is a shorthand for the [database_name].[schema_name].[object_name] format. I apologize, as I am also not clear on where this syntax is located in the official documentation, but it is indeed legal in SQL Server.

nene commented 10 months ago

Fixed in 15.1.0 release.