Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example doesn't work #168

Open
mgrandi opened this issue Jan 29, 2015 · 3 comments · Fixed by #255
Open

example doesn't work #168

mgrandi opened this issue Jan 29, 2015 · 3 comments · Fixed by #255

Comments

@mgrandi
Copy link

mgrandi commented Jan 29, 2015

The examples don't work, on python3.

1: they are not 2to3ed, so they don't run without changing the print statements
2: column_defs_lowlevel.py doesn't work, it parses the sql into a Statement, then uses token_next_by_instance() to find Parenthesis tokens.

However, the 'parsed' Statement's token_next_by_instance() goes through its token list, but its token list is vastly different then the token list flattened: (also seems the sql is parsed incorrectly, foo is not a function). So it passes the result of token_next_by_instance() which is None, and then it errors out.

But shouldn't token_next_by_instance recurse into the tokens in its token list? or how are you supposed to do stuff like this? use a token list like the example uses, or create a new token list from the 'flattened' tokens...but then you don't get the nested parent/children relationship

(Pdb) p parsed.tokens
[<DDL 'CREATE' at 0x100786598>, <Whitespace ' ' at 0x102245868>,
 <Keyword 'TABLE' at 0x102245818>, <Whitespace ' ' at 0x1022457c8>, 
<Function 'foo ( ...' at 0x10221d2c8>, <Punctuation ';' at 0x102274908>]

(Pdb) p list(parsed.flatten())
[<DDL 'CREATE' at 0x100786598>, <Whitespace ' ' at 0x102245868>, 
<Keyword 'TABLE' at 0x102245818>, <Whitespace ' ' at 0x1022457c8>, 
<Name 'foo' at 0x1022454f8>, <Whitespace ' ' at 0x10225bea8>,
 <Punctuation '(' at 0x10225bf98>, <Newline ' ' at 0x102274048>,
 <Whitespace ' ' at 0x102274098>, <Name 'id' at 0x1022740e8>,
 <Whitespace ' ' at 0x102274138>, <Builtin 'integer' at 0x102274188>, 
<Whitespace ' ' at 0x1022741d8>, <Keyword 'primary' at 0x102274228>, 
<Whitespace ' ' at 0x102274278>, <Keyword 'key' at 0x1022742c8>, 
<Punctuation ',' at 0x102274318>, <Newline ' ' at 0x102274368>,
 <Whitespace ' ' at 0x1022743b8>, <Name 'title' at 0x102274408>,
 <Whitespace ' ' at 0x102274458>, <Name 'varchar' at 0x1022744a8>, 
<Punctuation '(' at 0x1022744f8>, <Integer '200' at 0x102274548>,
 <Punctuation ')' at 0x102274598>, <Whitespace ' ' at 0x1022745e8>,
 <Keyword 'not nu...' at 0x102274638>, <Punctuation ',' at 0x102274688>, 
<Newline ' ' at 0x1022746d8>, <Whitespace ' ' at 0x102274728>,
 <Name 'descri...' at 0x102274778>, <Whitespace ' ' at 0x1022747c8>,
 <Builtin 'text' at 0x102274818>, <Newline ' ' at 0x102274868>, 
<Punctuation ')' at 0x1022748b8>, <Punctuation ';' at 0x102274908>]
@andialbrecht andialbrecht added this to the 0.1.15 milestone Feb 21, 2015
@andialbrecht andialbrecht removed this from the 0.1.15 milestone Apr 12, 2015
@vmuriart
Copy link
Contributor

This could be closed. compat solved this

@andialbrecht
Copy link
Owner

I'll keep this issue open. compat solves Python 3 issues, but the example is still broken since the parsing changed. I hope to get this fixed before doing a 0.2 release.

@vmuriart
Copy link
Contributor

Just realized the example is mis-recognizing one of the columns

ovr pushed a commit to cube-js/sqlparse that referenced this issue Dec 26, 2020
Fixes andialbrecht#168 by enabling `DATE` and other keywords to be used as
identifiers when not followed by a string literal.

A "typed string" is our term for generalized version of `DATE '...'`/`TIME '...'`/
`TIMESTAMP '...'` literals, represented as `TypedString { data_type, value }`
in the AST.

Unlike DATE/TIME/TIMESTAMP literals, this is a non-standard extension
supported by PostgreSQL at least.

This is a port of MaterializeInc/materialize#3146

Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
Co-authored-by: Nickolay Ponomarev <asqueella@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants