You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IF OBJECT_ID('tempdb..#Temp') IS NOT NULL
DROP TABLE #Temp
IF OBJECT_ID('temdb..#Temp2') IS NOT NULL
DROP TABLE #Temp2
....
In this order, the query runs in SQL Lab, but if I try to create a chart or save the dataset, I get the following error:
(156, b"Incorrect syntax near the keyword 'DECLARE'.DB-Lib error message 20018,....)
Alternatively, if I move the DECLARE and SELECT statements below "DROP TABLE #Temp2", the query again runs, but if I try to create a chart, I get the error:
Error parsing near 'OBJECT_ID' at line 4:12
Screenshots/recordings
No response
Superset version
4.1.1
Python version
3.9
Node version
16
Browser
Chrome
Additional context
No response
Checklist
I have searched Superset docs and Slack and didn't find a solution to my problem.
I have searched the GitHub issue tracker and didn't find a similar bug report.
I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
The text was updated successfully, but these errors were encountered:
Hey @huafist! 👋 I'm here to help you with any bugs, questions, or contributions you have for Superset. I'm a bot designed to assist you while you wait for a human maintainer. Let's tackle this issue together!
The issue you're encountering with the DECLARE statement in MSSQL when creating charts in Superset might be related to how Superset processes SQL queries for chart creation. While I couldn't find specific documentation on handling DECLARE statements, there are some configurations and settings in Superset that might affect query execution.
SQL Parsing and Execution: Superset might handle SQL parsing differently when creating charts compared to running queries in SQL Lab. This could lead to syntax errors if certain SQL constructs are not supported in the chart creation context.
Configurations Affecting Query Execution: There are configurations like SQLLAB_TIMEOUT, SQLLAB_HARD_TIMEOUT, and SQL_MAX_ROW that can impact query execution, but these are more related to time limits and row constraints rather than syntax issues [1].
MSSQL Specific Configurations: Recent updates have introduced improvements for MSSQL, such as supporting CTE in virtual tables and respecting the datefirst setting. However, these changes might not directly address the DECLARE statement issue [2].
To work around this issue, consider restructuring your query to avoid using DECLARE statements at the beginning, or try using alternative methods to set variables, such as using subqueries or CTEs. Additionally, ensure that any temporary tables are handled correctly within the query context.
I suspect that the issue is tied to the limit that superstack puts on the result of the query set. I'm guessing that it is injecting the "TOP XXXXX" directive in a way that's confusing the parser.
Bug description
SuperSet v4.1.1, MSSQL Server.
I have a query that starts with a DECLARE Statement:
DECLARE
@StartDate SMALLDATETIME,
@EndDate SMALLDATETIME
SELECT @StartDate = '20241201',
@EndDate = '20241231',
IF OBJECT_ID('tempdb..#Temp') IS NOT NULL
DROP TABLE #Temp
IF OBJECT_ID('temdb..#Temp2') IS NOT NULL
DROP TABLE #Temp2
....
In this order, the query runs in SQL Lab, but if I try to create a chart or save the dataset, I get the following error:
(156, b"Incorrect syntax near the keyword 'DECLARE'.DB-Lib error message 20018,....)
Alternatively, if I move the DECLARE and SELECT statements below "DROP TABLE #Temp2", the query again runs, but if I try to create a chart, I get the error:
Error parsing near 'OBJECT_ID' at line 4:12
Screenshots/recordings
No response
Superset version
4.1.1
Python version
3.9
Node version
16
Browser
Chrome
Additional context
No response
Checklist
The text was updated successfully, but these errors were encountered: