[Python] SQLAlchemy puts square brackets around SQL Server table name

Discussão em 'Python' iniciado por Stack, Janeiro 24, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to use SQLAlchemy with pyodbc using the Microsoft ODBC Driver for Linux, but when I use the session.query() function, I get the following error:


    pyodbc.ProgrammingError: ('42S02', "[42S02] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Invalid object name 'TableName'. (208) (SQLExecDirectW)")
    ​

    So I saw that the query created by ORM had square brackets on TableName.

    SELECT
    [mb.Tecnico].cod_tecnico AS [mb.Tecnico_cod_tecnico],
    [mb.Tecnico].nome AS [mb.Tecnico_nome],
    [mb.Tecnico].login AS [mb.Tecnico_login],
    [mb.Tecnico].senha AS [mb.Tecnico_senha]
    FROM
    [mb.Tecnico]
    ORDER BY
    [mb.Tecnico].nome

    Continue reading...

Compartilhe esta Página