paetzke / format-sql Goto Github PK
View Code? Open in Web Editor NEWMakes your SQL readable.
Home Page: http://format-sql.de
License: BSD 2-Clause "Simplified" License
Makes your SQL readable.
Home Page: http://format-sql.de
License: BSD 2-Clause "Simplified" License
I run the following command
format-sql a_sql_file.sql
but got the following error
Traceback (most recent call last):
File "/usr/local/bin/format-sql", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.5/dist-packages/format_sql/main.py", line 83, in main
_write_back(filename, lines, args.dry_run)
File "/usr/local/lib/python3.5/dist-packages/format_sql/main.py", line 148, in _write_back
f.write(lines)
TypeError: write() argument must be str, not None
exception when using WITH token in function
def _parse(toks):
raising InvalidSQL()
File "/usr/local/bin/format-sql", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/format_sql/main.py", line 83, in main
_write_back(filename, lines, args.dry_run)
File "/usr/local/lib/python2.7/dist-packages/format_sql/main.py", line 148, in _write_back
f.write(lines)
TypeError: expected a character buffer object
I've tried this with several files, including one ruby file with embedded SQL and then just with the SQL itself. Any insight into this? I'm just surprised that others aren't getting the same error.
Currently these are being unwrapped, so FROM {schema_name}.table_name
becomes schema_name table_name
.
Would it possible to have a switch to have the example in the README parsed like this
SELECT
country,
product,
SUM(profit)
FROM
sales
LEFT JOIN x ON -- note the difference here
x.id = sales.k -- possibly with more AND's, each AND in its line
GROUP BY
country,
product
HAVING
f > 7
AND -- and here
fk = 9
LIMIT 5;
I want to format this sql query but it's showing runtime error
=> https://github.com/yugyesh/song_play_analysis/blob/dev/sql_queries.py
See example, where did the ::
go?
from format_sql import format_sql
print('\n'.join(format_sql('SELECT cast::jsonb')))
>>> SELECT
>>> cast jsonb
The parser will fail to parse a query like select "id" from table
. This is DBMS specific, so this may actually be a parse error for other databases, but its how postgres does quoting of DDL-level stuff like columns and table names.
See this example snippet:
>>> format_sql.format_sql('''select a.a from aaa a where ((a.b+1) = 2);''')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/koerner/miniconda3/envs/tests-sql/lib/python3.6/site-packages/format_sql/shortcuts.py", line 20, in format_sql
parsed = list(parse(tokens))
File "/home/koerner/miniconda3/envs/tests-sql/lib/python3.6/site-packages/format_sql/parser.py", line 762, in parse
for statement, unused_count in _parse(toks):
File "/home/koerner/miniconda3/envs/tests-sql/lib/python3.6/site-packages/format_sql/parser.py", line 756, in _parse
statement, count = func(toks)
File "/home/koerner/miniconda3/envs/tests-sql/lib/python3.6/site-packages/format_sql/parser.py", line 596, in _parse_where
conditions, j = _parse_conditions(toks[1:])
File "/home/koerner/miniconda3/envs/tests-sql/lib/python3.6/site-packages/format_sql/parser.py", line 701, in _parse_conditions
raise InvalidCondition()
format_sql.parser.InvalidCondition
It seems that all (most?) queries with the following conditions <table>.<column> + 1 = <some other value>
fail to parse:
select a.a from aaa a where a.b+1 = 2;
This package is part of the pip repository manager for python, fine, but how do you use it from a python script? There is only information on how to run it as a binary.
Since this is standard (ANSI) SQL it should be supported :)
You can test with:
INSERT INTO spam
SELECT *
FROM eggs
Hi (thanks for the awesome software),
would the above be possible?
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.