sqlparse icon indicating copy to clipboard operation
sqlparse copied to clipboard

GRANT SELECT ON schema.object TO role; miscategorizes SELECT as the start of a statement for reindent=True

Open cfinkenstadt opened this issue 7 years ago • 1 comments

Reproduction in sqlparse 0.2.4:

>>> import sqlparse
>>> sqlparse.format("grant select on a_schema.an_object to a_role;", reindent=True, keyword_case='upper')
u'GRANT\nSELECT ON a_schema.an_object TO a_role;'
>>> sqlparse.format("grant select on a_schema.an_object to a_role;", reindent=False, keyword_case='upper')
u'GRANT SELECT ON a_schema.an_object TO a_role;'

expected output was u'GRANT SELECT...' in both examples.

Further example showing the extreme case:

>>> import sqlparse
>>> sqlparse.format("grant select, insert, update, delete, truncate on a_schema.an_object to a_role", keyword_case='upper', reindent=True)
u'GRANT\nSELECT,\nINSERT,\nUPDATE,\nDELETE, TRUNCATE ON a_schema.an_object TO a_role'
>>> sqlparse.format("grant select, insert, update, delete, truncate on a_schema.an_object to a_role", keyword_case='upper', reindent=False)
u'GRANT SELECT, INSERT, UPDATE, DELETE, TRUNCATE ON a_schema.an_object TO a_role'

cfinkenstadt avatar May 25 '18 15:05 cfinkenstadt

The same is with REVOKE but miscategorizes FROM and adds a linebreak GRANT SELECT ON ALL TABLES in SCHEMA PUBLIC TO umbrella; REVOKE SELECT ON TABLE customers FROM umbrella;

dkuku avatar Apr 13 '23 09:04 dkuku