Skip to content

[FORMATTING] tsql: GO should always be on a separate line #814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rmja opened this issue Dec 23, 2024 · 1 comment
Closed

[FORMATTING] tsql: GO should always be on a separate line #814

rmja opened this issue Dec 23, 2024 · 1 comment
Labels

Comments

@rmja
Copy link

rmja commented Dec 23, 2024

Input data

Which SQL and options did you provide as input?

CREATE OR ALTER VIEW Catalog.SomeView
WITH
    SCHEMABINDING AS
SELECT
    t.Id AS TableId
FROM
    Catalog.Table1 t
WHERE
    t.LastModified = 1
GO
CREATE UNIQUE CLUSTERED
INDEX IX_SomeView_TableId ON Catalog.SomeView (TableId);

Expected Output

CREATE OR ALTER VIEW Catalog.SomeView
WITH
    SCHEMABINDING AS
SELECT
    t.Id AS TableId
FROM
    Catalog.Table1 t
WHERE
    t.LastModified = 1
GO

CREATE UNIQUE CLUSTERED
INDEX IX_SomeView_TableId ON Catalog.SomeView (TableId);

or something similar. I believe it is reasonable to have GO at least on a separate line.
It signals the end of a batch of tsql statements, see https://learn.microsoft.com/en-us/sql/t-sql/language-elements/sql-server-utilities-statements-go?view=sql-server-ver16

Actual Output

CREATE OR ALTER VIEW Catalog.SomeView
WITH
    SCHEMABINDING AS
SELECT
    t.Id AS TableId
FROM
    Catalog.Table1 t
WHERE
    t.LastModified = 1 GO CREATE UNIQUE CLUSTERED
INDEX IX_SomeView_TableId ON Catalog.SomeView (TableId);

Usage

  • How are you calling / using the library? prettier-plugin-sql
  • What SQL language(s) does this apply to? tsql
  • Which SQL Formatter version are you using? 15.4.8
@rmja rmja added the bug label Dec 23, 2024
@nene nene closed this as completed in df4c535 Dec 23, 2024
@nene
Copy link
Collaborator

nene commented Dec 23, 2024

Thanks for reporting.

It seems that the support of Transact-SQL is really very problematic. Somebody contributed this long-long time ago, and looks like he simply copy-pasted the titles from documentation and declared it as syntax.

I patched this specific bug, but there are countless more like this. If you're really interested in improving the Transact-SQL support, I suggest you take a look at this list and replace it with syntax for beginnings of actual statements. Like currently it contains:

'AGGREGATE',
'APPLICATION ROLE',

But instead there should be:

'ALTER AGGREGATE',
'DROP AGGREGATE [IF EXISTS]',
'ALTER APPLICATION ROLE',
'CREATE APPLICATION ROLE',
'DROP APPLICATION ROLE',

Well, AGGREGATE and APPLICATION ROLE are probably the least interesting this. It doesn't support much more important stuff like CREATE {DATABASE|TRIGGER|SCHEMA|FUNCTION...}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants