Update mssql.py to use QUOTENAME in schema query#7641
Conversation
QUOTENAME adds [] around the values and handles eg. () in table names etc. With this addition table names will be correct for queries SELECT * FROM [data base 1].[dbo 2].[table name 3] will work But the current SELECT * FROM data base 1.dbo 2.table name 3 does not, the spaces lead to error in query
|
Thank you for your contribution ! Yes, some column names or some table names requires quotes or escapes. And, I see your point. But, that is not only for Microsoft SQL, but for almost all data source. I'm not sure what is the best solution. |
I am not familiar with other databases (that well) nor with the logics of this app more throughly. So this quick fix here and more extensive rework when someone has time and energy? |
|
I'm sorry I'm not so familiar with Microsoft SQL. |
|
Althouth it might not be common but bracket around the table, schema and database works with all of them still. |
|
Gemini Code Assist suggest small changes into phoenix.py |
|
Gemini code assist crashed a few times; there may be some inconsistencies in the files; it made changes to 28 files. |
|
"I'm sorry I'm not so familiar with Microsoft SQL. Well not using them is currently causing query errors or need to manually add them in editor, which is very frustrating. |
|
@gauiPPP can you post screen shot of what this error looks like in the Redash UI? |
|
I think changing all the query from like A to B make the SQL less readable and change the behavior largely. A: B: ("[procuct]" can be `product` depends on the data source.) |
|
I have been working with MS SQL queries soon 10 years and the editor I use has been kind enough to throw in the brackets so I do not get query errors with the spaces. A: |
|
I suppose I will fork or modify the code when I deploy, which will make updating a bit harder. I have been wondering why this issue, spaces in table names, has not been taken care of in Redash - or actually in some other SQL querying projects but I am slowly staring to find out:
|

QUOTENAME adds [] around the values and handles eg. () in table names etc. With this addition table names will be correct for queries SELECT * FROM [data base 1].[dbo 2].[table name 3] will work
But the current
SELECT * FROM data base 1.dbo 2.table name 3
does not, the spaces lead to error in query
What type of PR is this?
Description
How is this tested?
SQL query with old and new version, on MS SQL 2022 server
Related Tickets & Documents
I probably have suggested a change to this earlier. The issue has not gone away and QUOTENAME is probable the best solution for this; should work from MS SQL 1996 and up.
Mobile & Desktop Screenshots/Recordings (if there are UI changes)