sql-server - Unwanted square brackets inserted in SQL statement from ORM
问题描述
I'm trying to make a simple select on my table mapped with sqlalchemy but I can't get it to match the exact table name.
As I noticed, the output of this:
class Users(base):
__tablename__ = "users"
[...]
was
[Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'users'
And I tried to fix the error by explicitly writing the database I'm refering to
class Users(base):
__tablename__ = "[homework-3-cc-database].users"
[...]
giving the output:
[Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near ']'.
I noticed that it inserted some square brackets, unwanted. Here is their SQL statement:
[SQL: SELECT TOP 1 [[homework-3-cc-database].users].user_id AS [[homework-3-cc-database].users_user_id]
FROM [[homework-3-cc-database].users]]
This statement, ran from DataGrip works just fine:
SELECT TOP 1 [homework-3-cc-schema].users.user_id
FROM [homework-3-cc-schema].users
Do you have any suggestions regarding how should I fix this?
解决方案
我必须通过以下方式指定架构名称:
__table_args__ = {"schema": "homework-3-cc-schema"}
推荐阅读
- java - 客户端 REST 抛出 javax.ws.rs.NotFoundException
- java - java中的正则表达式处理程序
- ios - UICollectionView | 细胞可重复使用
- java - 如何不将控制器与视图关联?[圣杯]
- python - 使用 scipy 从所需位置旋转数组
- android - WebView 上方的 React Native 组件无法正确呈现
- javafx - 如何使用自己的控制器将文本字段从一个弹出窗口添加到主屏幕
- javascript - javascript中的函数一旦被触发就不起作用?
- javascript - ReactJS 和 ExtJS3 的问题
- javascript - 使用 lodash 将 JSON 转换为对象数组