betodealmeida commented on code in PR #36599:
URL: https://github.com/apache/superset/pull/36599#discussion_r2615961670
##########
superset/mcp_service/sql_lab/sql_lab_utils.py:
##########
@@ -206,8 +208,11 @@ def _execute_query(
def _is_select_query(sql: str) -> bool:
- """Check if SQL is a SELECT query."""
- return sql.lower().strip().startswith("select")
+ """Check if SQL is a SELECT query (including CTEs that start with WITH)."""
+ sql_lower = sql.lower().strip()
+ # SELECT queries start with SELECT
+ # CTE queries start with WITH and contain SELECT
+ return sql_lower.startswith("select") or sql_lower.startswith("with")
Review Comment:
You should use `SQLScript` and `SQLStatement` from `superset/sql/parse.py`
for all your parsing/AST checks/AST manipulation needs. Something like this
should work:
```python
script = SQLScript(sql, database.db_engine_spec.engine)
if script.has_mutation():
_process_select_results(cursor, results, limit)
else:
_process_dml_results(cursor, conn, results)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]