-
Notifications
You must be signed in to change notification settings - Fork 13.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: CTE queries with non-SELECT statements #25014
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but I'm worried about all the possible edge case we're missing.
I wonder if we should also use sqloxide to prevent false negatives. We'd try to parse with sqloxide, check for non-selects, return false if we do. If we don't, we then run the current flow with sqlparse.
>>> parse_sql("WITH a AS ( INSERT INTO foo (id) VALUES (1) RETURNING id ) SELECT * FROM a;", "ansi")
[{'Query': {'with': {'recursive': False, 'cte_tables': [{'alias': {'name': {'value': 'a', 'quote_style': None}, 'columns': []}, 'query': {'with': None, 'body': {'Insert': {'Insert': {'or': None, 'into': True, 'table_name': [{'value': 'foo', 'quote_style': None}], 'columns': [{'value': 'id', 'quote_style': None}], 'overwrite': False, 'source': {'with': None, 'body': {'Values': {'explicit_row': False, 'rows': [[{'Value': {'Number': ('1', False)}}]]}}, 'order_by': [], 'limit': None, 'offset': None, 'fetch': None, 'locks': []}, 'partitioned': None, 'after_columns': [], 'table': False, 'on': None, 'returning': [{'UnnamedExpr': {'Identifier': {'value': 'id', 'quote_style': None}}}]}}}, 'order_by': [], 'limit': None, 'offset': None, 'fetch': None, 'locks': []}, 'from': None}]}, 'body': {'Select': {'distinct': False, 'top': None, 'projection': [{'Wildcard': {'opt_exclude': None, 'opt_except': None, 'opt_rename': None, 'opt_replace': None}}], 'into': None, 'from': [{'relation': {'Table': {'name': [{'value': 'a', 'quote_style': None}], 'alias': None, 'args': None, 'with_hints': []}}, 'joins': []}], 'lateral_views': [], 'selection': None, 'group_by': [], 'cluster_by': [], 'distribute_by': [], 'sort_by': [], 'having': None, 'qualify': None}}, 'order_by': [], 'limit': None, 'offset': None, 'fetch': None, 'locks': []}}]
nice!, will try that! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3
(cherry picked from commit 3579861)
SUMMARY
Improves SQLLab parse check for non
SELECT
statements for CTE.The following statement was being accepted as a valid
SELECT
statement:BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION