DDL parsing broken

162 views
Skip to first unread message

Dimitri Vorona

unread,
Apr 30, 2015, 1:02:16 AM4/30/15
to sqlp...@googlegroups.com
Hi

to reproduce:

import sqlparse

sqlparse.parse("create table foo(a integer);")[0].tokens

[<DDL 'create' at 0x7fa5974103b8>,
 <Whitespace ' ' at 0x7fa597410408>,
 <Keyword 'table' at 0x7fa5974104f8>,
 <Whitespace ' ' at 0x7fa597410548>,
 <Function 'foo(a ...' at 0x7fa597400a48>,
 <Punctuation ';' at 0x7fa5974107c8>]

The table name 'foo' is identified as a function. It brakes examples/columns_def_lowlevel.py

Suggestions:

1. Add examples to test suits. 
2. Discuss how we should handle this case. Should table name be an identifier? I will create a pull request when we are clear on how the things should work

Regards
Dimitri.

Andi Albrecht

unread,
May 17, 2015, 2:22:33 PM5/17/15
to sqlp...@googlegroups.com
Hi Dimitri,

sorry for the late reply, I got stuck in a relocation for the past few weeks.

Yes, that's a known issue in sqlparse. The parser is currently pretty bad when it comes to DDLs. As far as I remember, the example just had a work around and got broken by a change that actually improved the parser. 

ATM sqlparse didn't really focus on a grammar which would be needed to correctyl parse the above mentioned statement. That's due to one of it's requirements: sqlparse should also work with broken statements that you often encounter in editors while working on a statement. So improving this isn't easy at all since sqlparse lacks a layer somewhere. But this is something I'd like to see fixed in one of the upcoming versions.

Best regards,

Andi

--
You received this message because you are subscribed to the Google Groups "sqlparse" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlparse+u...@googlegroups.com.
To post to this group, send email to sqlp...@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlparse.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages