File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -341,12 +341,15 @@ def group_aliased(tlist):
341341def group_functions (tlist ):
342342 has_create = False
343343 has_table = False
344+ has_as = False
344345 for tmp_token in tlist .tokens :
345346 if tmp_token .value == 'CREATE' :
346347 has_create = True
347348 if tmp_token .value == 'TABLE' :
348349 has_table = True
349- if has_create and has_table :
350+ if tmp_token .value == 'AS' :
351+ has_as = True
352+ if has_create and has_table and not has_as :
350353 return
351354
352355 tidx , token = tlist .token_next_by (t = T .Name )
Original file line number Diff line number Diff line change @@ -324,6 +324,11 @@ def test_grouping_alias_case():
324324 assert p .tokens [0 ].get_alias () == 'foo'
325325
326326
327+ def test_grouping_alias_ctas ():
328+ p = sqlparse .parse ('CREATE TABLE tbl1 AS SELECT coalesce(t1.col1, 0) AS col1 FROM t1' )[0 ]
329+ assert p .tokens [10 ].get_alias () == 'col1'
330+ assert isinstance (p .tokens [10 ].tokens [0 ], sql .Function )
331+
327332def test_grouping_subquery_no_parens ():
328333 # Not totally sure if this is the right approach...
329334 # When a THEN clause contains a subquery w/o parenthesis around it *and*
You can’t perform that action at this time.
0 commit comments