sqlparse icon indicating copy to clipboard operation
sqlparse copied to clipboard

Postgresql FROM clause table grouping

Open johnchenghk01 opened this issue 4 years ago • 0 comments

foo = """
select c1, c2, c3
from t1
left join t2
    on t1.c1 = t2.c2
, t3
where t1.c1 = t3.c3
"""

for x in list(sqlparse.parse(foo)[0]):
    if x.is_whitespace:
        continue
    print('----')
    print(type(x))
    print(x)
----
<class 'sqlparse.sql.Token'>
select
----
<class 'sqlparse.sql.IdentifierList'>
c1, c2, c3
----
<class 'sqlparse.sql.Token'>
from
----
<class 'sqlparse.sql.Identifier'>
t1
----
<class 'sqlparse.sql.Token'>
left join
----
<class 'sqlparse.sql.Identifier'>
t2
----
<class 'sqlparse.sql.Token'>
on
----
<class 'sqlparse.sql.IdentifierList'>
t1.c1 = t2.c2
, t3
----
<class 'sqlparse.sql.Where'>
where t1.c1 = t3.c3

The join condition and the third joining table are grouped into the same Identifier List. It should be separated, right?

ref: https://www.postgresql.org/docs/9.5/sql-select.html

johnchenghk01 avatar Aug 13 '20 05:08 johnchenghk01