Replies: 1 comment
-
Hiya, I replied in the corresponding Slack thread as well, just mirroring the answer here. Implementing analyses like the one you described where you infer & propagate constraints incrementally should be possible, SQLGlot is very powerful for these use cases. However, this is not something we plan to work on (i.e. the core team). Also note that syntax validation is not in scope, so there are no strong guarantees there. SQLGlot mostly detects simple errors like unbalanced parentheses, etc. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is it possible to say that SQL is not only syntacticly correct, but also makes sense semantically?
I know that without knowledge about the database schema it's difficult to say that specific SQL can be executed and will return results, but I believe with AST we can say that SQL is internally consistent/coherent.
Here are some examples
SELECT * FROM table
- assume*
is always correctSELECT col FROM table
- assumecol
is intable
so it's correctSELECT * from table as 't'
- is correct, assume 1SELECT 't'.col FROM table as 't'
- is correct, assume 2SELECT col FROM (SELECT * FROM table)
- is correct, assume 1 and 2SELECT 't'.col FROM (SELECT col FROM table) as 't'
- is correct, assume 4SELECT aliased_col FROM (SELECT col as 'aliased_col' FROM table)
- assume is correct, assume 2SELECT no_col FROM (SELECT col FROM table)
- is incorrect, because subquery has no columnno_col
in it's result, set of columns from outter select is not a subset of columns in subquery/inner select.And point 8 is what would be a great first step. I'm think that we could apply formal logic (https://pypi.org/project/mathesis/) to the AST and somehow figure out if the whole query make sense.
Anyway, I wanted to spark a discussion about validating SQL queries before executing them against db, since I haven't found a tool that could do such thing.
And here is a bit of something I wrote that partially do what I wanted as an effect, but not when it comes to the usage of formal logic.
Beta Was this translation helpful? Give feedback.
All reactions