0

I have a use case where I need to check the format of the sql query before sending to the the database for execution.

If sql query is not in correct format sqlparse should return the false status, if it is in correct format it should return true status.

I did not see any function in sqlparse docuementation for the same.

Example of my use case

This should return true:

select 
    count(users), 
    department 
from 
   usertable
group by department

This should return false:

select 
    count(users), 
    department,
    location 
from 
   usertable
group by department
Rahul Neekhra
  • 780
  • 1
  • 9
  • 39
  • 1
    I believe `sqlparse` is a non-validating parser. Perhaps something like https://pypi.org/project/sqlvalidator/ would be a better match – JonSG Apr 20 '23 at 14:32
  • When I used that I get below error File "C:\Users\Asus\AppData\Local\Programs\Python\Python310\lib\site-packages\sqlvalidator\grammar\lexer.py", line 426, in parse next_token = next(tokens) StopIteration Input SQL select count(EVT_ATT_1),EVT_ATT_1 from DETECTED_EVENTS group by; – Rahul Neekhra Apr 21 '23 at 08:07

0 Answers0