This extension allows you to utilize sqlfmt from within VS Code.
Operation
This extension is setup as a language formatter extension.
Meaning it can be set as the default formatter for sql files.
This gives you all the standard formatting in VS Code, such as formatting entire files or just highlighted sections.
For situations where you want to format SQL inside another file type, such as a string in another programming language, you can use the sqlfmt - Format SQL command.
This will run the program against the entire file or any highlighted text within any file type and replace it with the formatted result.
Settings
The list of settings can be seen in the FEATURES -> Settings tab of the extension details page.
Examples
Below are some examples of how various settings change the formatted result.
All examples use the following as the input SQL:
With Cte1
As (Select Column1,Column2 ,Column3, Column4 From Table1 )
,
Cte2 as ( select Column1
,Column2
FROM Table2)
Select
Distinct
Cte1.*,Cte2.Column2
From Cte1 inner join Cte2
ON Cte2.Column1 =Cte1.Column1
Order By
Cte1.Column2
Settings |
Result |
|
With Cte1
As (Select Column1, Column2, Column3, Column4 From Table1)
,
Cte2 as (select Column1
, Column2
FROM Table2)
Select
Distinct
Cte1.*, Cte2.Column2
From Cte1 inner join Cte2
ON Cte2.Column1 = Cte1.Column1
Order By
Cte1.Column2
|
|
With Cte1 As (Select Column1, Column2, Column3, Column4 From Table1),
Cte2 as (select Column1, Column2 FROM Table2)
Select Distinct
Cte1.*,
Cte2.Column2
From Cte1
inner join Cte2 ON Cte2.Column1 = Cte1.Column1
Order By Cte1.Column2
|
- Replace Newlines
- Uppercase
|
WITH Cte1 AS (SELECT Column1, Column2, Column3, Column4 FROM Table1),
Cte2 AS (SELECT Column1, Column2 FROM Table2)
SELECT DISTINCT
Cte1.*,
Cte2.Column2
FROM Cte1
INNER JOIN Cte2 ON Cte2.Column1 = Cte1.Column1
ORDER BY Cte1.Column2
|
- Replace Newlines
- Lowercase
- Space Count = 2
|
with Cte1 as (select Column1, Column2, Column3, Column4 from Table1),
Cte2 as (select Column1, Column2 from Table2)
select distinct
Cte1.*,
Cte2.Column2
from Cte1
inner join Cte2 on Cte2.Column1 = Cte1.Column1
order by Cte1.Column2
|
- Replace Newlines
- Char Count = 50
|
With Cte1 As (
Select
Column1,
Column2,
Column3,
Column4
From Table1
),
Cte2 as (select Column1, Column2 FROM Table2)
Select Distinct
Cte1.*,
Cte2.Column2
From Cte1
inner join Cte2 ON Cte2.Column1 = Cte1.Column1
Order By Cte1.Column2
|
- Replace Newlines
- Uppercase
- Tabs
- Char Count = 40
|
WITH Cte1 AS (
SELECT
Column1,
Column2,
Column3,
Column4
FROM Table1
),
Cte2 AS (
SELECT
Column1,
Column2
FROM Table2
)
SELECT DISTINCT
Cte1.*,
Cte2.Column2
FROM Cte1
INNER JOIN Cte2 ON Cte2.Column1 = Cte1.Column1
ORDER BY Cte1.Column2
|
| |