Code Monkey home page Code Monkey logo

sqlparse's People

Contributors

adamgreenhall avatar andialbrecht avatar cclauss avatar dagwieers avatar darikg avatar dbczumar avatar dlenski avatar fredyw avatar jdufresne avatar john-bodley avatar johshoff avatar kilowu avatar koljonen avatar kwstubbs avatar mrmasterplan avatar phdru avatar pidelport avatar piranna avatar r33s3n6 avatar rowanseymour avatar rygwdn avatar shenlongxing avatar sjoerdjob avatar soloman1124 avatar spigwitmer avatar timgraham avatar twang2218 avatar vmuriart avatar wind39 avatar yriveiro 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  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  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  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

sqlparse's Issues

Support for "if not exists" expression in "create table" statement

_This is a _shadow issue* for Issue 29 on Google Code (from which this project was moved).
Added 2011-01-03T18:34:17.000Z by [email protected]. Closed (Duplicate).
Labels: Type-Defect, Priority-Medium, Splitter.
Please make updates to the bug there.*

Original description

The following expression is possible for MySQL for example:

    CREATE TABLE IF NOT EXISTS table_name(...);

sqlparse does not recognize any statements after such expression. Some code snippet to reproduce:

    import sqlparse
    a = sqlparse.split("""
        drop table a; 
        create table if not exists a ( id int );
        dropt table b;""")
    len(a) # len(a) = 2, should be 3 here

Although the support of SQL standards in MySQL is well known (it's bad) such constructions can appear in database dump for sure.

"null" keyword can cause stairs when reindenting

_This is a _shadow issue* for Issue 50 on Google Code (from which this project was moved).
Added 2011-09-29T21:59:53.000Z by [email protected].
Labels: Type-Defect, Priority-Medium.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
python -c 'import sqlparse; print sqlparse.format(&quot;SELECT foo, null bar, car FROM dual&quot;, reindent = True);'

<b>What is the expected output? What do you see instead?</b>
I would expect something like:

SELECT      foo,
       null bar,
            car
FROM dual

but instead get:

SELECT foo,
       null bar,
            car
FROM dual

<b>What version of the product are you using? On what operating system?</b>
Tested with both 0.1.3 and head on CentOS 5.4, python 2.7.

Fromatter adds additional new line after comments

_This is a _shadow issue* for Issue 3 on Google Code (from which this project was moved).
Added 2009-03-30T10:33:14.000Z by albrecht.andi. Closed (Fixed).
Labels: Type-Defect, Priority-Low, Component-Formatter.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
>>> import sqlparse
>>> print(sqlparse.format('select -- a comment\nfrom foo', reindent=True))
select -- a comment

from foo
>>> 

<b>What is the expected output? What do you see instead?</b>
There should be no additional new line after &quot;-- a comment&quot;.


<b>Please use labels and text to provide additional information.</b>

Incorrect case modification for some identifiers

_This is a _shadow issue* for Issue 32 on Google Code (from which this project was moved).
Added 2011-01-15T18:50:45.000Z by [email protected]. Closed (Fixed).
Labels: Type-Defect, Priority-High.
Please make updates to the bug there.*

Original description

Original query: select m.id, m.name from main m where m.open=1

Invocation arguments: sqlformat -k upper -i lower -r --indent_width=4 -

Resulting query:

SELECT M.id, M.name
FROM main M
WHERE M.OPEN=1

Expected result:

SELECT m.id, m.name
FROM main m
WHERE m.open=1

Formatter shouldn't change identifiers in double quotes

_This is a _shadow issue* for Issue 21 on Google Code (from which this project was moved).
Added 2010-08-26T17:44:56.000Z by albrecht.andi. Closed (Fixed).
Labels: Type-Defect, Priority-Medium, Milestone-0.1.2.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
1. echo 'select &quot;foo&quot; from bar'|bin/sqlformat -i &quot;upper&quot; -
<b>2.</b>
<b>3.</b>

<b>What is the expected output? What do you see instead?</b>

ouput: select &quot;FOO&quot; from BAR

&quot;foo&quot; shouldn't be changed at all.


<b>Please use labels and text to provide additional information.</b>

Wrong identifier grouping in CREATE TABLE table_name AS SELECT ....

_This is a _shadow issue* for Issue 8 on Google Code (from which this project was moved).
Added 2009-07-13T16:11:37.000Z by [email protected]. Closed (Fixed).
Labels: Type-Defect, Priority-Medium, Version-0.1.1, Milestone-0.1.2.
Please make updates to the bug there.*

Original description

When parsing a query like this:

CREATE TABLE example_table AS SELECT * from example_table_2;

This token list is produced:

[<DDL 'CREATE' at 0x297c690>,
 <Whitespace ' ' at 0x297c650>,
 <Keyword 'TABLE' at 0x297c750>,
 <Whitespace ' ' at 0x297c790>,
 <Identifier 'exampl...' at 0x2b9a7c0>,
 <Whitespace ' ' at 0x297c910>,
 <Wildcard '*' at 0x297c950>,
 <Whitespace ' ' at 0x297c990>,
 <Keyword 'from' at 0x297c9d0>,
 <Whitespace ' ' at 0x297ca10>,
 <Identifier 'exampl...' at 0x2b9a830>,
 <Punctuation ';' at 0x297cad0>]

Notice that in the above list:
 <Identifier 'exampl...' at 0x2b9a7c0>,

has &quot;consumed&quot; the select DDL. Below are the tokens in <Identifier 'exampl... :

[<Name 'exampl...' at 0x297c7d0>,
 <Whitespace ' ' at 0x297c810>,
 <Keyword 'AS' at 0x297c850>,
 <Whitespace ' ' at 0x297c890>,
 <DML 'SELECT' at 0x297c8d0>]

The solution is for the identifiers to get grouped only when a non sql
reserved keyword follows.

VARCHAR2 is missing

_This is a _shadow issue* for Issue 16 on Google Code (from which this project was moved).
Added 2010-07-29T16:40:14.000Z by [email protected]. Closed (Fixed).
Labels: Type-Enhancement, Priority-Medium, Milestone-0.1.2.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
1. parse a CREATE TABLE statement with a VARCHAR2
<b>2.</b>
<b>3.</b>

<b>What is the expected output? What do you see instead?</b>
VARCHAR2 is not recognized as Token.Name.Builtin

<b>What version of the product are you using? On what operating system?</b>
0.1.1

<b>Please provide any additional information below.</b>

Use callable objects for filters

_This is a _shadow issue* for Issue 43 on Google Code (from which this project was moved).
Added 2011-09-04T12:57:30.000Z by piranna.
Labels: Type-Enhancement, Priority-Medium.
Please make updates to the bug there.*

Original description

At this moment, a filter is a class with just a process() method inside it. I propose to use instead callable objects (objects with a __call__() method) so it's more standard and the most simple filters would be regular python functions since in fact functions in python are callable objects.

Also, allowing the pipeline system that the stream is mutable it would allow to use directly functions of other libraries without glue code. The only thing is that the functions should return a generator for optimization, but this is not neccesary.

As a last point, it should be set as deprecated the process() style. At this moment the pipeline system is backbard compatible and it wouldn't be difficult make it also the full library, but in a later version i think it should be necesary.

formatter crashes when sql contains text not in utf8

_This is a _shadow issue* for Issue 20 on Google Code (from which this project was moved).
Added 2010-08-12T08:29:42.000Z by [email protected].
Labels: Type-Defect, Priority-Medium, Incomplete.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
1. Create sql file with comments in russian encoded with cp1251
2. Feed it to formatter

<b>What is the expected output? What do you see instead?</b>
I expect comments to stay &quot;as is&quot;. I see python stack trace instead.

<b>What version of the product are you using? On what operating system?</b>
Current version; win32 platform.

Programmatically retrieve column definitions from CREATE and ALTER statements

_This is a _shadow issue* for Issue 5 on Google Code (from which this project was moved).
Added 2009-04-23T06:45:19.000Z by albrecht.andi.
Labels: Type-Enhancement, Priority-Medium, Parser.
Please make updates to the bug there.*

Original description

The Statement class should provide functions to programmatically retrieve
column definitions.

The attached file contains an example implementation of the low-level
parsing. See this thread on the mailing list for API ideas: 
http://groups.google.com/group/sqlparse/browse_thread/thread/4c1e6e22484ad07c

Handle [] with AS more gracefully when indenting

_This is a _shadow issue* for Issue 27 on Google Code (from which this project was moved).
Added 2010-12-04T00:03:42.000Z by [email protected]. Closed (Fixed).
Labels: Type-Enhancement, Priority-Medium.
Please make updates to the bug there.*

Original description

some variants of SQL allow [name with blanks] to specify a name with embedded blanks.

you could say:
str = '''select a.[fist name], a.[last name], a.city
from tab;'''


sqlparse.format(str, reindent=True, indent_tabs=False)
returns:
select a.[fist name] as field1,
                   a.[last name] as field2,
                           a.city
from tab;

Right parenthesis is put inside the wrong token group

_This is a _shadow issue* for Issue 9 on Google Code (from which this project was moved).
Added 2009-09-11T17:04:37.000Z by [email protected]. Closed (Fixed).
Labels: Type-Defect, Priority-Medium, Version-0.1.1, Milestone-0.1.2.
Please make updates to the bug there.*

Original description

Sqlparse puts the right parenthesis inside a 'Where' group for certain queries

<b>What steps will reproduce the problem?</b>

> s=sqlparse.parse('select * from (select * from test where rowid!=1)')[0]
> s.tokens[6]
<Parenthesis '(selec...' at 0x1df8050>
> s.tokens[6].tokens 
[<Punctuation '(' at 0x1dfba70>,
 <DML 'select' at 0x1dfb998>,
 <Whitespace ' ' at 0x1dfb908>,
 <Wildcard '*' at 0x1dfb9e0>,
 <Whitespace ' ' at 0x1dfb950>,
 <Keyword 'from' at 0x1dfbab8>,
 <Whitespace ' ' at 0x1dfbb00>,
 <Identifier 'test' at 0x1df8320>,
 <Whitespace ' ' at 0x1dfbb90>,
 <Where 'where ...' at 0x1df8140>]

<b>What is the expected output? What do you see instead?</b>
I would expect at the end of the parenthesis group (above) to see something
like:
<Punctuation ')' at 0xxxxxxx>

<b>What version of the product are you using? On what operating system?</b>
2 months old sqlparse from the hg repository on linux

<b>Please provide any additional information below.</b>

zczx

_This is a _shadow issue* for Issue 48 on Google Code (from which this project was moved).
Added 2011-09-29T03:27:40.000Z by [email protected]. Closed (Invalid).
Labels: Type-Defect, Priority-Medium.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
<b>1.</b>
<b>2.</b>
<b>3.</b>

<b>What is the expected output? What do you see instead?</b>


<b>What version of the product are you using? On what operating system?</b>


<b>Please provide any additional information below.</b>

Bug splitting several statements in a query

_This is a _shadow issue* for Issue 44 on Google Code (from which this project was moved).
Added 2011-09-13T00:20:47.000Z by piranna.
Labels: Type-Defect, Priority-Medium.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
1. Try to split a query with several statements using a StatementFilter() (in my case, i use it indirectly throught split2() ) when there are no space between the last word of the statement and the semicolon.

<b>What is the expected output? What do you see instead?</b>
It should split the statements correctly, but in fact, it thread the word and the semicolon as an only one token. If you put a space between them, it split correctly showing me two statements inside the query.

<b>What version of the product are you using? On what operating system?</b>
SVN HEAD version, Ubuntu 11.04 x64

<b>Please provide any additional information below.</b>

This is the working query with the space after the INSERT query, if you remove it it doesn't work:

-- Split the chunks in the database in two (old-head and new-tail)
-- based on it's defined length

-- Create new chunks containing the tail sectors and
-- update the old chunks length to contain only the head sectors

INSERT INTO chunks(file, block,           length,           sector)
            SELECT file, block+:length+1, length-:length-1, sector+:length+1
            FROM chunks
            WHERE file IS :file
              AND block = :block ;

UPDATE chunks SET length  = :length
WHERE file IS :file
  AND block = :block;

VARCHAR2 is missing

_This is a _shadow issue* for Issue 17 on Google Code (from which this project was moved).
Added 2010-07-29T16:41:53.000Z by [email protected]. Closed (Duplicate).
Labels: Type-Defect, Priority-Medium.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
1. parse a CREATE TABLE statement with a VARCHAR2
<b>2.</b>
<b>3.</b>

<b>What is the expected output? What do you see instead?</b>
VARCHAR2 is not recognized as Token.Name.Builtin

<b>What version of the product are you using? On what operating system?</b>
0.1.1

<b>Please provide any additional information below.</b>

comments by themselves are not parsed properly

_This is a _shadow issue* for Issue 26 on Google Code (from which this project was moved).
Added 2010-12-01T09:15:46.000Z by Glyph.Lefkowitz. Closed (Fixed).
Labels: Type-Defect, Priority-Medium, Version-0.1.2.
Please make updates to the bug there.*

Original description

>>> sqlparse.parse('--hello')[0].tokens[0].tokens
[<Operator '-' at 0x100550ed0>, <Operator '-' at 0x100550f10>, <Identifier 'hello' at 0x100548c20>]
>>> sqlparse.parse('--hello\n\n')[0].tokens
[<Single '--hell...' at 0x100562090>, <Newline ' ' at 0x100562190>]
>>> sqlparse.parse('--')[0].tokens
[<Operator '-' at 0x1005621d0>, <Operator '-' at 0x100562210>]

however, add even an invalid statement and suddenly the comment can be parsed:

>>> sqlparse.parse('--\n;')[0].tokens
[<Comment '-- ' at 0x100548c20>, <Punctuation ';' at 0x100562250>]

"Stair" when mixing table-qualified column names and function calls

_This is a _shadow issue* for Issue 45 on Google Code (from which this project was moved).
Added 2011-09-23T23:41:18.000Z by [email protected]. Closed (Fixed).
Labels: Type-Defect, Priority-Medium, Version-0.1.3.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>

python -c 'import sqlparse; print sqlparse.format (&quot;SELECT t.c1, t.c2, COALESCE(t.c3, t.c4), COALESCE(t.c5, t.c6), t.c7 FROM t;&quot;, reindent = True);'


<b>What is the expected output? What do you see instead?</b>

The expected output would be left-aligning &quot;t.&quot; and COALESCE:

| SELECT t.c1,
|        t.c2,
|        COALESCE(t.c3, t.c4),
|        COALESCE(t.c5, t.c6),
|        t.c7
| FROM t;

Instead I see a &quot;stair&quot;:

| SELECT t.c1,
|          t.c2,
|            COALESCE(t.c3, t.c4),
|            COALESCE(t.c5, t.c6),
|            t.c7
| FROM t;


<b>What version of the product are you using? On what operating system?</b>

0.1.3 on Python 2.6 (Linux).


<b>Please provide any additional information below.</b>

The formatting of &quot;SELECT c1, c2, COALESCE(c3, c4), COALESCE(c5, c6), c7 FROM t;&quot; and &quot;SELECT t.c1, t.c2, t.c3, t.c5, t.c7 FROM t;&quot; is &quot;correct&quot; (= to my taste :-)).

Select clauses incorrectly reindented when CASE clause present

_This is a _shadow issue* for Issue 46 on Google Code (from which this project was moved).
Added 2011-09-28T15:02:29.000Z by [email protected]. Closed (Fixed).
Labels: Type-Defect, Priority-Medium, Version-0.1.3.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
Run the command:
python -c 'import sqlparse; print sqlparse.format(&quot;SELECT foo, bar, CASE WHEN foo < bar THEN 1 ELSE 0 END foobar, car FROM DUAL WHERE 1 = 1&quot;, reindent = True);'

<b>What is the expected output? What do you see instead?</b>
I would expect something like:

SELECT foo,
       bar,
       CASE
           WHEN foo < bar THEN 1
           ELSE 0
       END foobar,
       car
FROM DUAL
WHERE 1 = 1

but instead get:

SELECT foo, bar, CASE
                     WHEN foo < bar THEN 1
                     ELSE 0
                 END foobar,
                     car
FROM DUAL
WHERE 1 = 1

This isn't a problem for short lists of select clauses like this example, but makes the output nearly unreadable for long lists of select clauses.

<b>What version of the product are you using? On what operating system?</b>
Tested with both 0.1.3 and head on CentOS 5.4, python 2.7.

Web app doesn't handle non-utf-8 files correctly

_This is a _shadow issue* for Issue 42 on Google Code (from which this project was moved).
Added 2011-08-03T08:21:26.000Z by albrecht.andi.
Labels: Type-Defect, Priority-Medium, webapp.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
1. Upload the attached file at sqlformat.appspot.com
2. Click &quot;Format&quot;
3. 500

<b>What is the expected output? What do you see instead?</b>


<b>Please use labels and text to provide additional information.</b>

"key" column interpreted as keyword by indenter

_This is a _shadow issue* for Issue 47 on Google Code (from which this project was moved).
Added 2011-09-28T15:10:47.000Z by [email protected]. Closed (Fixed).
Labels: Type-Defect, Priority-Medium, Version-0.1.3.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
Run the command:
python -c 'import sqlparse; print sqlparse.format(&quot;SELECT foo.foo, foo.key, foo.bar FROM foo WHERE 1 = 1&quot;, reindent = True);'

<b>What is the expected output? What do you see instead?</b>
I would expect something like:

SELECT foo.foo,
       foo.key,
       foo.bar
FROM foo
WHERE 1 = 1

but instead get:

SELECT foo.foo,
       foo.key, foo.bar
FROM foo
WHERE 1 = 1

I suspect that the parser is interpreting the &quot;key&quot; of foo.key as a keyword and is getting confused as a result.

<b>What version of the product are you using? On what operating system?</b>
Tested with both 0.1.3 and head on CentOS 5.4, python 2.7.

Support for placeholders

_This is a _shadow issue* for Issue 22 on Google Code (from which this project was moved).
Added 2010-11-12T01:07:18.000Z by Glyph.Lefkowitz. Closed (Fixed).
Labels: Type-Enhancement, Priority-Medium.
Please make updates to the bug there.*

Original description

sqlparse thinks that &quot;?&quot; is an operator, and treats &quot;:a&quot; as a piece of punctuation and then an identifier.  &quot;$1&quot; is an error.

It would be nice if sqlparse supported at least one form of placeholder syntax.

Identifier.value is None

_This is a _shadow issue* for Issue 30 on Google Code (from which this project was moved).
Added 2011-01-06T18:31:43.000Z by albrecht.andi.
Labels: Type-Defect, Priority-Medium, Version-0.1.2, Parser.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>

>>> import sqlparse
>>> p = sqlparse.parse('select foo')[0]
[<DML 'select' at 0xb70d0e0c>,
 <Whitespace ' ' at 0xb70d0e4c>,
 <Identifier 'foo' at 0xb70d241c>]
>>> p.tokens[-1].value is None
<<< True 
>>> str(p.tokens[-1])
<<< 'foo'

<b>What is the expected output? What do you see instead?</b>
Identifier.value should be 'foo' too.

<b>Please use labels and text to provide additional information.</b>

column constraints parsed incorrectly if there are any more columns

_This is a _shadow issue* for Issue 24 on Google Code (from which this project was moved).
Added 2010-12-01T06:27:04.000Z by Glyph.Lefkowitz.
Labels: Type-Enhancement, Priority-Medium.
Please make updates to the bug there.*

Original description

&quot;create table a (b integer not null, c integer)&quot; is parsed incorrectly; sqlparse sees an IdentifierList of 'null, c'.

&quot;create table a (b integer, c integer not null)&quot;, however, gets parsed correctly, because there's no comma after the NULL.

This also happens with a 'references x' constraint on the first column, except then the IdentifierList contains the name of the column and the next column.

Make it easier to identify the operands of an operator

_This is a _shadow issue* for Issue 23 on Google Code (from which this project was moved).
Added 2010-11-12T01:15:16.000Z by Glyph.Lefkowitz.
Labels: Type-Enhancement, Priority-Medium.
Please make updates to the bug there.*

Original description

Consider the results when sqlparse parses the string:

    &quot;select (3 + 4) = 7 and (5 + 6) = 11;&quot;

It identifies &quot;3 + 4 = 7&quot; as a &quot;Comparison&quot;, which is questionable; it's really an expression.

More importantly, sqlparse doesn't identify the outer 'and' expression as a Comparison of its own, either; it just sees Comparison, Keyword, Comparison.

Finally I'd like to be able to strip out the parenthesis tokens and easily see just the expression structure, rather than the syntactic structure.  (Don't get me wrong, being able to preserve byte-for-byte input is great; it's just not always what is most of interest when I'm processing stuff.)

sqlformat formats between ... add ... clause badly

_This is a _shadow issue* for Issue 14 on Google Code (from which this project was moved).
Added 2010-06-16T12:13:29.000Z by [email protected]. Closed (Fixed).
Labels: Type-Defect, Priority-Medium.
Please make updates to the bug there.*

Original description

Format this with sqlformat -r -ilower -:
select 
    timestamp::date,
    count(*)
from logs
where 
    db_id = 123
    and user_id = 123
    and timestamp between '2010-05-01'::timestamp and '2010-05-30'::timestamp
group by timestamp::date

Result would be:
SELECT TIMESTAMP::date, COUNT(*)
FROM logs
WHERE db_id = 123
  AND user_id = 123
  AND TIMESTAMP BETWEEN '2010-05-01'::TIMESTAMP
  AND '2010-05-30'::TIMESTAMP
GROUP BY TIMESTAMP::date

formatting clause and z between x and y
as 
'''
and z between x
and y
'''
obscures it instead of making it more readable

Lexer shouldn't unfiy line breaks

_This is a _shadow issue* for Issue 1 on Google Code (from which this project was moved).
Added 2009-03-22T12:25:16.000Z by albrecht.andi. Closed (Fixed).
Labels: Type-Defect, Priority-Medium.
Please make updates to the bug there.*

Original description

Currently the lexer unifies line breaks to UNIX LE. It should preserve the
line endings given in the original string (maybe even if it contains mixed
line endings).

Formatter fails on identifier list in nested queries

_This is a _shadow issue* for Issue 4 on Google Code (from which this project was moved).
Added 2009-04-21T13:47:06.000Z by albrecht.andi. Closed (Fixed).
Labels: Type-Defect, Priority-Low, Component-Formatter.
Please make updates to the bug there.*

Original description

Example statement:

select * from (select x.foo, x.bar as foo2, x.baz from mytable)

Results in:

SELECT *
FROM
  (SELECT x.foo,
          x.bar AS foo2,
                   x.baz
   FROM mytable)

This doesn't happen when the inner statement is formatted on it's own.

incorrect formatting when aliasing a sub select

_This is a _shadow issue* for Issue 40 on Google Code (from which this project was moved).
Added 2011-07-20T19:50:42.000Z by [email protected]. Closed (Fixed).
Labels: Type-Defect, Priority-Medium.
Please make updates to the bug there.*

Original description

python -c &quot;import sqlparse; print sqlparse.format('SELECT id, name FROM (SELECT id, name FROM bar)', reindent=True)&quot;

SELECT id,
       name
FROM
  (SELECT id,
          name
   FROM bar)

python -c &quot;import sqlparse; print sqlparse.format('SELECT id, name FROM (SELECT id, name FROM bar) as foo', reindent=True)&quot;

SELECT id,
       name
FROM
  (SELECT id, name
   FROM bar) as foo


When aliasing the subselect the query is not formatted properly (no new line after id, ).

Bug in split() with IF in a SELECT query

_This is a _shadow issue* for Issue 33 on Google Code (from which this project was moved).
Added 2011-02-10T18:56:50.000Z by [email protected]. Closed (Fixed).
Labels: Type-Defect, Priority-Medium, Version-0.1.2, Milestone-0.1.3, Splitter.
Please make updates to the bug there.*

Original description

I tried to split with sqlparse.split() the following query:
'CREATE TEMPORARY TABLE tmp SELECT IF(a=1, a, b) AS o FROM one; SELECT t FROM two'

It returns only 1 query instead of 2:
[u'CREATE TEMPORARY TABLE tmp SELECT IF(a=1, a, b) AS o FROM one; SELECT t FROM two']

It is apparently a problem caused by the IF (without it, sqlparse returns 2 queries).

Wrong indentation if column wrapped in function call

_This is a _shadow issue* for Issue 36 on Google Code (from which this project was moved).
Added 2011-05-14T13:57:38.000Z by [email protected]. Closed (Fixed).
Labels: Type-Defect, Priority-Medium, Version-0.1.2, Formatter, Milestone-0.1.3.
Please make updates to the bug there.*

Original description

I expect:

>>> code = 'SELECT MAX(COLA) &quot;a&quot;, COLB &quot;b&quot;, COLC &quot;c&quot; FROM t;'
>>> print sqlparse.format(code, reindent=True)
SELECT MAX(COLA) &quot;a&quot;,
       COLB &quot;b&quot;,
       COLC &quot;c&quot;
FROM t;

I get:

>>> code = 'SELECT MAX(COLA) &quot;a&quot;, COLB &quot;b&quot;, COLC &quot;c&quot; FROM t;'
>>> print sqlparse.format(code, reindent=True)
SELECT MAX(COLA) &quot;a&quot;,
                 COLB &quot;b&quot;,
                 COLC &quot;c&quot;
FROM t;

It gets even worse when more than one columns are wrapped in a function call.

>>> code = 'SELECT MAX(COLA) &quot;a&quot;, MAX(COLB) &quot;b&quot;, COLC &quot;c&quot; FROM t;'
>>> print sqlparse.format(code, reindent=True)
SELECT MAX(COLA) &quot;a&quot;, MAX(COLB) &quot;b&quot;,
                                COLC &quot;c&quot;
FROM t;


Software environment:
sqlparse 0.1.2
Python 2.6.6 (r266:84292, Jan  4 2011, 16:45:45) 
Mac OS X 10.6.7

Fromatter looses spaces before LIMIT when reindent=True

_This is a _shadow issue* for Issue 35 on Google Code (from which this project was moved).
Added 2011-04-13T13:46:51.000Z by albrecht.andi. Closed (Fixed).
Labels: Type-Defect, Priority-Medium, Formatter, Milestone-0.1.3, Version-0.1.2.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
>>> import sqlparse
>>> sqlparse.format(&quot;select * from foo where bar = 1 limit 1&quot;, reindent=True)
<<< u'select *\nfrom foo\nwhere bar = 1limit 1'


<b>What is the expected output? What do you see instead?</b>

Output should read u'select *\nfrom foo\nwhere bar = 1 limit 1' (space before limit)


<b>Please use labels and text to provide additional information.</b>

Improve performance of reindent

_This is a _shadow issue* for Issue 41 on Google Code (from which this project was moved).
Added 2011-07-29T18:43:31.000Z by albrecht.andi.
Labels: Type-Defect, Priority-High.
Please make updates to the bug there.*

Original description

Reindent filter has a lousy performance on certain statements. One of the &quot;statements of death&quot; is attached.

The problem is that ReindentFilter._get_offset() is a performance hog. The number of calls to flatten() in offset calculation is totally insane. 

Possible solutions are:
- remember offsets
- limit flatten() range
- reimplement reindent using a different approach

One problem is that the statement changes constantly in this phase of processing and I'm not sure if it makes sense to store some kind of state at all.

NB, this causes DeadlineExceeded errors on App Engine

LONG is missing

_This is a _shadow issue* for Issue 19 on Google Code (from which this project was moved).
Added 2010-07-30T09:43:51.000Z by [email protected]. Closed (Fixed).
Labels: Type-Enhancement, Priority-Medium, Milestone-0.1.2.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
1. parse a CREATE statement with a field using LONG as type
<b>2.</b>
<b>3.</b>

<b>What is the expected output? What do you see instead?</b>
LONG recognized as Name.Builtin, instead it's not recognized

<b>What version of the product are you using? On what operating system?</b>
0.1.1

<b>Please provide any additional information below.</b>

Wrong parsing of nvl in where or and clause

_This is a _shadow issue* for Issue 37 on Google Code (from which this project was moved).
Added 2011-06-10T08:24:20.000Z by [email protected].
Labels: Type-Defect, Priority-Medium, Incomplete.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
1. Parse a query with a nvl statement in a where or and. E.g.:

   SELECT *    
     FROM table1 tab1
     JOIN table2 tab2 ON tab1.id = tab2.id
    WHERE SYSDATE BETWEEN tab1.date1 AND NVL(tab2.date2,SYSDATE)

<b>What is the expected output? What do you see instead?</b>
Expected to find that &quot;tab1.id&quot; and &quot;tab2.id&quot; would be parsed as Identifier instead they are split into two tokens with type name and a token with type punctuation.

<b>What version of the product are you using? On what operating system?</b>
sqlparse 0.1.2 (from Python Package Index)
python 2.7.1
windows xp

Error 500 when formatting file

_This is a _shadow issue* for Issue 31 on Google Code (from which this project was moved).
Added 2011-01-12T15:08:21.000Z by [email protected].
Labels: Type-Defect, Priority-Medium, webapp.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
1. Run the attached file

<b>What is the expected output? What do you see instead?</b>
I expect to see the file formatting according to the default formatting options.  Instead I get a 500 error.


<b>What version of the product are you using? On what operating system?</b>
I was using the free online version on a Windows Server 2003 server.

<b>Please provide any additional information below.</b>

token.match does not ignore case for DDL

_This is a _shadow issue* for Issue 34 on Google Code (from which this project was moved).
Added 2011-03-16T09:15:19.000Z by [email protected]. Closed (Fixed).
Labels: Type-Defect, Priority-Medium, Milestone-0.1.3, Version-0.1.2.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
1. run the following script

import sqlparse
t = sqlparse.parse(&quot;create&quot;)[0].token_first()
t.match(&quot;CREATE&quot;) #returns false, doesn't make sense


<b>What is the expected output? What do you see instead?</b>

Last line should return true, DDL is still a keyword


<b>What version of the product are you using? On what operating system?</b>

latest release, on linux


<b>Please provide any additional information below.</b>

The problem is, that match ignores case only for Keyword, it should check if Keyword is one of your descendants.

columns whose names start with 'create' or 'end' are misparsed

_This is a _shadow issue* for Issue 25 on Google Code (from which this project was moved).
Added 2010-12-01T06:31:24.000Z by Glyph.Lefkowitz. Closed (Duplicate).
Labels: Type-Defect, Priority-Medium.
Please make updates to the bug there.*

Original description

&quot;create table a (ended timestamp)&quot; or &quot;create table a (created timestamp)&quot; results in a keyword token 'end' and then an identifier token 'ed', or 'create', 'd' respectively.

This can be fixed by adjusting the 'END' and 'CREATE' regular expressions in Lexer.tokens['root'] to begin and end with '\b', to require word boundaries.

Tab indentation doesn't produce usable results

_This is a _shadow issue* for Issue 6 on Google Code (from which this project was moved).
Added 2009-05-06T16:35:36.000Z by albrecht.andi.
Labels: Type-Defect, Priority-Low, Version-0.1.0.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
1. Format a statement with reindent=True and indent_tabs=True

<b>What is the expected output? What do you see instead?</b>

Expected output is a nicely formatted statement, but the formatter
calulates indentations based on spaces. Maybe indentation using tabs will
be removed.


<b>Please use labels and text to provide additional information.</b>

Literals are not added to identifier lists

_This is a _shadow issue* for Issue 2 on Google Code (from which this project was moved).
Added 2009-03-27T04:57:17.000Z by albrecht.andi. Closed (Fixed).
Labels: Type-Defect, Priority-Medium, Component-Parser.
Please make updates to the bug there.*

Original description

Example statement:

select null, foo, bar from mytable;

&quot;null&quot; should be added to identifier list, so that e.g. formatting with
reindent returns

select null,
       foo,
       bar
from mytable;

problem parsing create table statement generated by django for sqlite

_This is a _shadow issue* for Issue 28 on Google Code (from which this project was moved).
Added 2010-12-22T12:39:20.000Z by [email protected].
Labels: Type-Defect, Priority-Medium.
Please make updates to the bug there.*

Original description

This is a result of interactive session:

In [35]: sqlparse.parse('''CREATE TABLE auth_user_user_permissions (&quot;id&quot; integer NOT NULL PRIMARY KEY,
    &quot;user_id&quot; integer NOT NULL,
    &quot;permission_id&quot; integer NOT NULL REFERENCES &quot;auth_permission&quot; (&quot;id&quot;),
    UNIQUE (&quot;user_id&quot;, &quot;permission_id&quot;)
)
''')
Out[40]: (<Statement 'CREATE...' at 0xb7217d4c>,)

In [41]: x = _[0].tokens

In [42]: x
Out[42]: 
[<DDL 'CREATE' at 0xb722048c>,
 <Whitespace ' ' at 0xb72204ac>,
 <Keyword 'TABLE' at 0xb72204cc>,
 <Whitespace ' ' at 0xb72204ec>,
 <Function 'auth_u...' at 0xb721f1b4>,
 <Newline ' ' at 0xb7220bcc>]

I wanted to parse columns from this statement, but none was returned.

Indent issue with named function column in select

_This is a _shadow issue* for Issue 10 on Google Code (from which this project was moved).
Added 2010-01-08T15:12:13.000Z by paul.bridger.
Labels: Type-Defect, Priority-Medium.
Please make updates to the bug there.*

Original description

v0.1.1
Using reindent = True

At some stage I'll dig into the code to find the problem here, but if
someone fixes it before I get around to it that would be wonderful. :)

Formatted SQL is:

SELECT SERIAL# SERIAL,
       SERVICE_NAME SERVICE_NAME,
       P1 WAIT_P1,
       P2 WAIT_P2,
       P3 WAIT_P3,
       ROW_WAIT_ROW# ROW_WAIT_ROW,
       ROW_WAIT_OBJ# ROW_WAIT_OBJ,
       ROW_WAIT_BLOCK# ROW_WAIT_BLOCK,
       ROW_WAIT_FILE# ROW_WAIT_FILE,
       DECODE(STATE,'WAITING',
                    'WAITING',
                    'ON CPU') WAIT_STATE,
                              DECODE(STATE,'WAITING',
                                           WAIT_CLASS,
                                           'ON CPU') WAIT_CLASS,
                                                     DECODE(STATE,'WAITING',
                                                                  EVENT,
                                                                  'ON CPU')
WAIT_EVENT, SID SID, AUDSID AUDSID, USERNAME USERNAME, MACHINE MACHINE,
CLIENT_IDENTIFIER CLIENT_IDENTIFIER, COMMAND COMMAND, STATUS STATUS,
PROCESS PROCESS, PROGRAM PROGRAM, TYPE TYPE, CLIENT_INFO CLIENT_INFO,



                                     SQL_HASH_VALUE SQL_HASH_VALUE,



                                     SQL_ID SQL_ID,



                                     PLAN_HASH_VALUE PLAN_HASH_VALUE,



                                     MODULE MODULE,



                                     ACTION ACTION,



                                     LOGON_TIME LOGON_TIME,



                                     LAST_CALL_ET LAST_CALL_ET,



                                     FIXED_TABLE_SEQUENCE FIXED_TABLE_SEQUENCE,



                                     WAIT_CLASS WAIT_CLASS,



                                     SECONDS_IN_WAIT SECONDS_IN_WAIT,



                                     WAIT_TIME WAIT_TIME,



                                     PLSQL_ENTRY_OBJECT_ID
PLSQL_ENTRY_OBJECT_ID,



                                     PLSQL_ENTRY_SUBPROGRAM_ID
PLSQL_ENTRY_SUBPROGRAM_ID,



                                     PLSQL_OBJECT_ID PLSQ

NOT NULL, next_field_name is parsed as an sqlparse.sql.IdentifierList

_This is a _shadow issue* for Issue 18 on Google Code (from which this project was moved).
Added 2010-07-29T17:30:41.000Z by [email protected]. Closed (Fixed).
Labels: Type-Defect, Priority-Medium, Version-0.1.1, Milestone-0.1.2.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
1. end a field definition with CONSTRAINT constraint_name NOT NULL,
2. start the next field with field_name
<b>3.</b>

<b>What is the expected output? What do you see instead?</b>
&quot;NULL&quot; &quot;,&quot; and &quot;field_name&quot; as separate tokens, however you get an IdentifierList instead

<b>What version of the product are you using? On what operating system?</b>
0.1.1

<b>Please provide any additional information below.</b>

incorrect formatting when using mysql with a table named user

_This is a _shadow issue* for Issue 39 on Google Code (from which this project was moved).
Added 2011-07-19T19:51:47.000Z by [email protected]. Closed (Fixed).
Labels: Type-Defect, Priority-Medium, Parser.
Please make updates to the bug there.*

Original description

Hi,

python -c &quot;import sqlparse; print sqlparse.format('select foo.id, foo.name from user', reindent=True)&quot;
select foo.id,
       foo.name
from user


python -c &quot;import sqlparse; print sqlparse.format('select user.id, user.name from user', reindent=True)&quot;
select user.id, user.name
from user


The second query is not formatted properly (no newline after user.id) because sqlparse thinks user is a keyword which it is not the case for mysql.

One way to fix this would be to quote the table name:

python -c 'import sqlparse; print sqlparse.format(&quot;&quot;&quot;select &quot;user&quot;.id, &quot;user&quot;.name from user&quot;&quot;&quot;, reindent=True)'
select &quot;user&quot;.id,
       &quot;user&quot;.name
from user


But I can't do that because my queries are automatically generated by SQLAlchemy, instead I monkey patched sqlparse to use the list of keywords provided by SQLAlchemy in sqlalchemy.dialects.mysql.base

Would you consider a patch adding a dialect option to sqlparse ?

Comments at the end do not get correctly dectected

_This is a _shadow issue* for Issue 38 on Google Code (from which this project was moved).
Added 2011-06-10T09:55:11.000Z by [email protected]. Closed (Fixed).
Labels: Type-Defect, Priority-Medium.
Please make updates to the bug there.*

Original description

>>> import sqlparse
u'SELECT * FROM user; -- why!\n-- hello\n'
>>> sqlparse.format('-- hello\nSELECT * FROM user;\n-- hello\n', strip_comments=True)
u'SELECT * FROM user;\n-- hello\n'
>>> sqlparse.format('-- hello\nSELECT * FROM user; -- hello\n-- hello\n', strip_comments=True)
u'SELECT * FROM user; -- hello\n-- hello\n'

Making the following change fixes the issue

diff -r 96cf90d0f248 sqlparse/engine/grouping.py
--- a/sqlparse/engine/grouping.py   Wed Apr 13 16:04:56 2011 +0200
+++ b/sqlparse/engine/grouping.py   Fri Jun 10 10:54:34 2011 +0100
@@ -229,6 +229,7 @@
                                        [lambda t: t.ttype in T.Comment,
                                         lambda t: t.is_whitespace()])
         if end is None:
+            tlist.group_tokens(sql.Comment, [token])
             idx = tidx + 1
         else:
             eidx = tlist.token_index(end)

"role" as last table in "from" clause prevents newlines from being printed in "from" clause

_This is a _shadow issue* for Issue 49 on Google Code (from which this project was moved).
Added 2011-09-29T21:52:44.000Z by [email protected].
Labels: Type-Defect, Priority-Medium.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
python -c 'import oldsqlparse; print oldsqlparse.format(&quot;SELECT foo FROM bar,role WHERE 1 = 1&quot;, reindent = True);'

<b>What is the expected output? What do you see instead?</b>
I would expect something like:

SELECT foo
FROM bar,
     role
WHERE 1 = 1

but get:

SELECT foo
FROM bar,role
WHERE 1 = 1

instead.

<b>What version of the product are you using? On what operating system?</b>
Tested with both 0.1.3 and head on CentOS 5.4, python 2.7.

<b>Please provide any additional information below.</b>
I suspect &quot;role&quot; is being interpreted as some sort of keyword here.

Include patches from extras/py3k/fixes.diff

_This is a _shadow issue* for Issue 12 on Google Code (from which this project was moved).
Added 2010-01-09T21:37:19.000Z by albrecht.andi. Closed (Fixed).
Labels: Type-Defect, Priority-Medium, Version-0.1.1, Milestone-0.1.2.
Please make updates to the bug there.*

Original description

extras/py3k/fixes.diff contains two fixes that need to be applied when using 
the 2to3 tool to produce a Python 3 version of sqlparse. These fixes should 
go into sqlparse itself to avoid extra patching.

Statements with escape characters \' do sometimes not recognize end of statement

_This is a _shadow issue* for Issue 13 on Google Code (from which this project was moved).
Added 2010-03-22T06:14:56.000Z by [email protected]. Closed (Fixed).
Labels: Type-Defect, Priority-Medium, Milestone-0.1.2.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>
Take the following Statements:
insert into database_address (id, street, zip, city, state, country_id, 
comment ) values(41, '7, Rue De L\'Eperon', '75006','Paris','', (select id 
from database_country where name = 'France'), 'Box/Building: ');
insert into database_address (id, street, zip, city, state, country_id, 
comment ) values(42, 'Eisenbahnstr. 41', '79098','Freiburg','', (select id 
from database_country where name = 'Germany'), 'Box/Building: ');
insert into database_address (id, street, zip, city, state, country_id, 
comment ) values(43, 'Grillparzerstr. 46', '81675','München','', (select id 
from database_country where name = 'Germany'), 'Box/Building: ');

<b>What is the expected output? What do you see instead?</b>
I would expect thst these statements are parsed as 3 seperate statements.

<b>What version of the product are you using? On what operating system?</b>
Version: Not sure. 
OS: Ubuntu 9.04

'create' is tokenized even when embedded in another word (e.g. "created")

_This is a _shadow issue* for Issue 7 on Google Code (from which this project was moved).
Added 2009-06-24T00:12:18.000Z by [email protected]. Closed (Fixed).
Labels: Type-Defect, Priority-Medium, Version-0.1.1, Milestone-0.1.2.
Please make updates to the bug there.*

Original description

<b>What steps will reproduce the problem?</b>

sqlparse.format(&quot;create table created_test ( name text, created date )&quot;, 
    keyword_case='upper', 
    identifier_case='lower')

<b>What is the expected output? What do you see instead?</b>

expected:

u'CREATE TABLE created_test ( name text, created date )'

actual:

u'CREATE TABLE CREATEd_test ( name text, CREATEd date )'


<b>What version of the product are you using? On what operating system?</b>
Mac OS X 10.5/10.6

$ sudo easy_install sqlparse
Password:
Searching for sqlparse
Best match: sqlparse 0.1.1
Processing sqlparse-0.1.1-py2.6.egg
sqlparse 0.1.1 is already the active version in easy-install.pth
Installing sqlformat script to /usr/local/bin

Using /Library/Python/2.6/site-packages/sqlparse-0.1.1-py2.6.egg
Processing dependencies for sqlparse
Finished processing dependencies for sqlparse

<b>Please provide any additional information below.</b>

I was able to get the expected results, without seeming to break anything else, with the following:

--- sqlparse-0.1.1/sqlparse/lexer.py    2009-05-05 21:59:02.000000000 -0700
+++ sqlparse-0.1.1-mod/sqlparse/lexer.py    2009-06-23 16:27:45.000000000 -0700
@@ -174,7 +174,7 @@
             (r'&quot;(&quot;&quot;|[^&quot;])*&quot;', String.Symbol), # not a real string literal in ANSI SQL
             (r'(LEFT |RIGHT )?(INNER |OUTER )?JOIN', Keyword),
             (r'END( IF| LOOP)?', Keyword),
-            (r'CREATE( OR REPLACE)?', Keyword.DDL),
+            (r'CREATE( OR REPLACE)?\b', Keyword.DDL),
             (r'[a-zA-Z_][a-zA-Z0-9_]*', is_keyword),
             (r'\$([a-zA-Z_][a-zA-Z0-9_]*)?\$', Name.Builtin),
             (r'[;:()\[\],\.]', Punctuation),

Please note: I'm very nearly completely parser-illiterate, and so can't even begin to guess at whether that was even remotely 
the right thing to do, but it *seemed* to work for me

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.