pablormira / sql_formatter Goto Github PK
View Code? Open in Web Editor NEWA Python based SQL formatter
Home Page: https://pablormira.github.io/sql_formatter/
License: Apache License 2.0
A Python based SQL formatter
Home Page: https://pablormira.github.io/sql_formatter/
License: Apache License 2.0
something like
select asdf
from table; /* some comment */
would be wrongly separated from the next query like
select asdf
from table;
/* some comment */
Currently, case when
will be formatted without breaklines like
SELECT field1,
case when field2 < 1 then 1 when field2 >=1 and field2 < 5 then 2 else 3 end as field2_cat
...
and I would like to have some indentation like
SELECT field1,
case when field2 < 1 then 1
when field2 >=1 and field2 < 5 then 2
else 3 end as field2_cat
...
Add validation for case when ... end correctly written. Sometimes I forgot the end
Test interaction to pre-commit to check that the CLI can be used to automatically format SQL files with pre-commit
Up to now we also format SQL comments with --
Release first version of the package and publish to pipy and anaconda
All done! seems misleading because it could also mean everything is already formatted before program execution
There is no formatting for PARTITION BY clausels, e.g.
SELECT asdf,
row_number() OVER (PARTITI
ON BY qwer
ORDER BY asdf)
The newline for ON in PARITITION is rather a general problem as in #26
SELECT asdf,
row_number() OVER (PARTITION BY qwer
ORDER BY asdf)
Specially something like
select asdf, qwer
/* bla bla */
/* bla bla 2 */
asdf2
from table1
will be marked as
select asdf, qwer
[CS]/* bla bla */[C] [CI] /* bla bla 2 */[C]
asdf2
from table1
This is wrong: [CI] is only for newlines within multiline comments
Allow the user to mark queries somewhat to not format them, e.g. using something like /*formatter-skip*/
This is the case if there is some special keyword in between like COMMENT, e.g.:
CREATE OR REPLACE VIEW my_view COMMENT='blabla' AS
in that case we wrongly get
CREATE OR REPLACE VIEW MY_VIEW comment='blabla' AS
Expected behavior: Untouched
Something like
sql-formatter -r *.sql
with default False
e.g.
ON a.field1 = b.field1 and a.field and a.field2 = b.field2
to
ON a.field1 = b.field1 and
a.field2 = b.field2
sql-formatter sql_file.sql
introduces 3 newlines at the beginning of file after formatting
Specially if somebody wants to install from Source:
via pip
sql-formatter sql_file.sql
separates function arguments in SELECT as if they were normal fields, e.g.
SELECT asdf,
substr(asdf,
3,
1) as substr_asdf
SELECT asdf,
substr(asdf, 3, 1) as substr_asdf
Setup: how to install development environment and so on
ON formatting function formats also words containing "on", like function. Consider the following query:
SELECT asdf,
my_function
FROM ...
The formatter then does
SELECT asdf,
my_functi
ON
FROM ...
SELECT asdf,
my_function
FROM ...
Closely related to #23
ORDER BY is not being formatted
ORDER BY should be formatted like GROUP BY
check_sql_query()
should identify create .* table
If there are no balanced parenthesis then abort formatting
Related to #52
E.g.
select asdf,
case when asdf >= 1 and asdf <= 10 and substr(qwer, 1, 2) = 'abc' and substr(qwer, 3, 2) = 'qwerty' then 1
else 0 end as case_field,
asdf2
from table1
should be formatted as
select asdf,
case when asdf >= 1 and
asdf <= 10 and
substr(qwer, 1, 2) = 'abc' and
substr(qwer, 3, 2) = 'qwerty' then 1
else 0 end as case_field,
asdf2
from table1
CREATE TABLE asdf AS
SELECT qwer
FROM table1 <- no semicolon
CREATE TABLE asdf2 AS
...
Only SELECT is formatted. SELECT DISTINCT does not get proper indentation
Something like
CREATE TASK bla bla
CREATE TABLE my_table AS
should not return a warning.
Only CREATE TABLE / VIEW twice should return a warning
something like
select asdf,
case when asdf = 1 and -- some comment
asdf != 2 then 1 else 0 end as some_field
from table1
would be formatted like
select asdf,
case when asdf = 1 and -- some comment
asdf != 2 then 1 else 0 end as some_field
from table1
and not better like
select asdf,
case when asdf = 1 and -- some comment
asdf != 2 then 1 else 0 end as some_field
from table1
E.g.
format_where()
is not robust against keywords and
and or
in comments
Kind of reformatting afterwards
Specially useful for SELECT and ON lines
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.