pythonsql-serversqlalchemypyodbc

SQLAlchemy + Python Mapping, Do I have to map every column from SQL Server DB or can I map only the columns I need?


One of many tables in SQL Server database has far more columns than I need, upwards of 40-50, and I only need 5 or 6 of them. Can I map only the columns I need?


Solution

  • Yes.

    From docs.sqlalchemy.org

    Sometimes, a Table object was made available using the reflection process described at Reflecting Database Objects to load the table’s structure from the database. For such a table that has lots of columns that don’t need to be referenced in the application, the include_properties or exclude_properties arguments can specify that only a subset of columns should be mapped.