Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[FORMATTING] GO Statement Before Procedure Declaration #606

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
grantwforsythe opened this issue Jun 8, 2023 · 5 comments
Closed

[FORMATTING] GO Statement Before Procedure Declaration #606

grantwforsythe opened this issue Jun 8, 2023 · 5 comments
Labels

Comments

@grantwforsythe
Copy link
Contributor

Input data

SET
NOCOUNT ON;

GO

CREATE OR ALTER PROCEDURE dbo.sp_say_hi (@Name VARCHAR(25) = 'World')
AS BEGIN
    PRINT CONCAT('Hello, ', @Name);
END;

Expected Output

SET
NOCOUNT ON;

GO

CREATE
OR ALTER
PROCEDURE dbo.sp_say_hi (@Name VARCHAR(25) = 'World')
AS BEGIN
    PRINT CONCAT('Hello, ', @Name);
END;

The GO statement should be on it's own line.

Actual Output

SET
NOCOUNT ON;

GO CREATE
OR ALTER
PROCEDURE dbo.sp_say_hi (@Name VARCHAR(25) = 'World') AS BEGIN
    PRINT CONCAT('Hello, ', @Name);
END;

When executed on the database a fatal error occurs (Incorrect syntax was encountered while CREATE was being parsed) because of the GO.

Usage

  • How are you calling / using the library?
    The library is being called from a Git hook with the below config:
    {
      "language": "tsql",
      "tab width": 4,
      "useTabs": false,
      "keywordCase": "upper",
      "indentStyle": "standard",
      "logicalOperatorNewline": "before",
      "expressionWidth": 80,
      "linesBetweenQueries": 2,
      "denseOperators": false,
      "newlineBeforeSemicolon": false
    }
  • What SQL language(s) does this apply to?
    Transact-SQL/T-SQL
  • Which SQL Formatter version are you using?
    Latest (v12.2.2)
nene added a commit that referenced this issue Jun 9, 2023
@nene
Copy link
Collaborator

nene commented Jun 9, 2023

Thanks, the fix is now released in 12.2.2

@Jackesque
Copy link

Jackesque commented Mar 24, 2025

Hi, somehow this issue still persists.

This is the desired output:

USE master;

GO
DROP DATABASE test;

GO
CREATE DATABASE test;

GO
USE test;

GO

Yet this is the output:

USE master;

GO
DROP DATABASE test;

GO CREATE DATABASE test;

GO USE test;

GO

Please address and fix it. I'm using the VSCode extension. My OS is Windows 10.

I tested in the website, and it gave the same result:

Image

@nene
Copy link
Collaborator

nene commented Mar 24, 2025

Thanks for reporting.

The problem here is that this is not really about how the GO statement is supported, but rather how all other statements that can come after GO are supported. I threw in some support for CREATE/ALTER/DROP DATABASE and USE statements. But that's only a needle in the haystack - a lot more is missing. I personally have zero experience with the Microsoft SQL stack. Somebody contributed the Transact-SQL support a long time ago, but turns out that he simply copy-basted the chapter titles from the documentation as syntax, which doesn't really work :P So as a result the Transact-SQL support in SQL Formatter is really pretty crappy. Additionally I've come to understand that there really are multiple SQL languages gathered under the Transact-SQL label. The primary one is for SQL Server, but then there's also Azure and various other things. So this probably should be split up to multiple dialects on SQL Formatter side. Buty I'm not too keen on working on improving this as I find the syntax diagrams in MS docs to be kinda hard to comprehend.

I should point out though that you haven't selected Transact-SQL as the SQL dialect you're formatting (see also the FAQ):

Image

Given the state of Transact-SQL support, this might actually make some things worse.

@Jackesque
Copy link

After changing the dialect, the result did change, just not in any significantly helpful way. Thanks for the reply though.

The result using Transact-SQL:

USE master;

GO DROP
DATABASE test;

GO CREATE
DATABASE test;

GO USE test;

GO

Desired output:

USE master;

GO
DROP DATABASE test;

GO
CREATE DATABASE test;

GO
USE test;

GO

@nene
Copy link
Collaborator

nene commented Mar 26, 2025

The fix for the latter has now been released in 15.5.2

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

3 participants