Closed dwoodleych closed 2 years ago
If there is a single column in group by the identifier is not included in IdentifierList
import sqlparse
rawsql = "SELECT Test1, Test2, SUM(Test3) from tblTest GROUP BY Test1, Test2"
querysql = sqlparse.format(rawsql, encoding=None, reindent_aligned=True) parsed = sqlparse.parse(querysql) stmt = parsed[0]
for t in stmt: if type(t) == sqlparse.sql.IdentifierList: print(t)
Yields:
Test1, Test2, SUM(Test3) Test1, Test2
and then the following code with a single column in GROUP BY
rawsql = "SELECT Test1, Test2, SUM(Test3) from tblTest GROUP BY Test1"
yields:
Test1, Test2, SUM(Test3)
I'm an idiot
If there is a single column in group by the identifier is not included in IdentifierList
import sqlparse
rawsql = "SELECT Test1, Test2, SUM(Test3) from tblTest GROUP BY Test1, Test2"
querysql = sqlparse.format(rawsql, encoding=None, reindent_aligned=True) parsed = sqlparse.parse(querysql) stmt = parsed[0]
for t in stmt: if type(t) == sqlparse.sql.IdentifierList: print(t)
Yields:
Test1, Test2, SUM(Test3) Test1, Test2
and then the following code with a single column in GROUP BY
import sqlparse
rawsql = "SELECT Test1, Test2, SUM(Test3) from tblTest GROUP BY Test1"
querysql = sqlparse.format(rawsql, encoding=None, reindent_aligned=True) parsed = sqlparse.parse(querysql) stmt = parsed[0]
for t in stmt: if type(t) == sqlparse.sql.IdentifierList: print(t)
yields:
Test1, Test2, SUM(Test3)