Giter Site home page Giter Site logo

format-sql's People

Contributors

paetzke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

format-sql's Issues

TypeError: write() argument must be str, not None

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

not WITH token

exception when using WITH token in function
def _parse(toks):

raising InvalidSQL()

TypeError: expected a character buffer object

  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.

AND (and more) on their own line

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;

:: cast replaced by empty space

See example, where did the :: go?

from format_sql import format_sql
print('\n'.join(format_sql('SELECT cast::jsonb')))
>>> SELECT
>>>    cast jsonb

Can't parse quoted fields (postgres)

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.

Parse error in where clausel when using operations on a term

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;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.