Skip to content

mssql dialect improperly quotes object (table/column) names containing ']' #5467

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

Closed
gordthompson opened this issue Jul 17, 2020 · 2 comments
Closed
Assignees
Labels
bug Something isn't working SQL Server Microsoft SQL Server, e.g. mssql sql
Milestone

Comments

@gordthompson
Copy link
Member

gordthompson commented Jul 17, 2020

Describe the bug
The mssql dialect improperly quotes object (e.g., table/column) names containing ']' characters.

Expected behavior
The dialect should escape ']' characters as ']]' like the T-SQL function QUOTENAMES does.

To Reproduce

meta = sa.MetaData()
table_name = "colo[u]r"
tbl = sa.Table(table_name, meta, sa.Column("id", sa.Integer))
meta.create_all(engine)

Error

sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near 'r'. (102) (SQLExecDirectW)")
[SQL: 
CREATE TABLE [colo[u]r] (
	id INTEGER NULL
)

]
@gordthompson gordthompson added bug Something isn't working sql SQL Server Microsoft SQL Server, e.g. mssql labels Jul 17, 2020
@gordthompson gordthompson added this to the 1.3.x milestone Jul 17, 2020
@gordthompson gordthompson self-assigned this Jul 17, 2020
@sqla-tester
Copy link
Collaborator

Gord Thompson has proposed a fix for this issue in the master branch:

Fix mssql dialect escaping object names containing ']' https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/2097

@sqla-tester
Copy link
Collaborator

Gord Thompson has proposed a fix for this issue in the rel_1_3 branch:

Fix mssql dialect escaping object names containing ']' https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/2098

sqlalchemy-bot pushed a commit that referenced this issue Jul 19, 2020
Fixes: #5467
Change-Id: I054ec219717ba62847a9daf1214e215dd6b70633
(cherry picked from commit 547e959)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SQL Server Microsoft SQL Server, e.g. mssql sql
Projects
None yet
Development

No branches or pull requests

2 participants