Skip to content
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

MSSQL SuperSet Incorect Syntax near the Keyword 'DECLARE' when attempting to create chart with a valid query. #31913

Open
2 of 3 tasks
huafist opened this issue Jan 17, 2025 · 3 comments
Labels
data:connect:mssql Related to MSSSQL viz:charts Namespace | Anything related to viz types

Comments

@huafist
Copy link

huafist commented Jan 17, 2025

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

  • 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.
Copy link

dosubot bot commented Jan 17, 2025

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.

  1. 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.

  2. 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].

  3. 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.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@rusackas rusackas added the data:connect:mssql Related to MSSSQL label Jan 17, 2025
@rusackas
Copy link
Member

@sujiplr is the only person on our little rolodex who uses MSSQL... perhaps he can reproduce this or provide some input.

@dosubot dosubot bot added the viz:charts Namespace | Anything related to viz types label Jan 17, 2025
@huafist
Copy link
Author

huafist commented Jan 18, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data:connect:mssql Related to MSSSQL viz:charts Namespace | Anything related to viz types
Projects
None yet
Development

No branches or pull requests

2 participants