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

"Create Table table_name Like existing_table_name" DDL Support #543

Open
reata opened this issue Apr 11, 2020 · 1 comment · May be fixed by #767
Open

"Create Table table_name Like existing_table_name" DDL Support #543

reata opened this issue Apr 11, 2020 · 1 comment · May be fixed by #767

Comments

@reata
Copy link

reata commented Apr 11, 2020

When parsing Create Table Like DDL:

create table tab1 like tab2;

"tab1 like tab2" as a whole will be parsed as Comparison. I think this is different situation from Comparison used in where clause. Any comments on this one?

@reata
Copy link
Author

reata commented Mar 28, 2021

This is introduced by #525 and released in 0.3.1 version

As in v0.3.0

>>> sqlparse.parse("CREATE TABLE tab1 LIKE tab2;")[0].tokens
[<DDL 'CREATE' at 0x7F37552F1468>,
 <Whitespace ' ' at 0x7F37552FC048>,
 <Keyword 'TABLE' at 0x7F37552FC0A8>,
 <Whitespace ' ' at 0x7F37552FC108>,
 <Identifier 'tab1' at 0x7F37552F90C0>,
 <Whitespace ' ' at 0x7F37552FC1C8>,
 <Keyword 'LIKE' at 0x7F37552FC228>,
 <Whitespace ' ' at 0x7F37552FC288>,
 <Identifier 'tab2' at 0x7F37552F9138>,
 <Punctuation ';' at 0x7F37552FC348>]

As in v0.3.1

>>> sqlparse.parse("CREATE TABLE tab1 LIKE tab2;")[0].tokens
[<DDL 'CREATE' at 0x7F2CE8DD89A8>,
 <Whitespace ' ' at 0x7F2CE8DD8A68>,
 <Keyword 'TABLE' at 0x7F2CE8DD8AC8>,
 <Whitespace ' ' at 0x7F2CE8DD8B28>,
 <Comparison 'tab1 L...' at 0x7F2CE8DAF840>,
 <Punctuation ';' at 0x7F2CE8DD88E8>]

For our case when LIKE appear in a DDL, to be parsed as KEYWORD in 0.3.0 is correct, however in 0.3.1, to address LIKE appear in WHERE clause, LIKE is parsed as COMPARISON even in DDL, which is wrong.

markjm added a commit to markjm/sqlparse that referenced this issue Mar 12, 2024
markjm added a commit to markjm/sqlparse that referenced this issue Mar 12, 2024
markjm added a commit to markjm/sqlparse that referenced this issue Mar 12, 2024
markjm added a commit to markjm/sqlparse that referenced this issue Mar 12, 2024
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.

1 participant