sqlparse
sqlparse copied to clipboard
"Create Table table_name Like existing_table_name" DDL Support
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?
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.