Describe the bug
Problem
When reflecting a SQL Server table that uses the built-in SYSNAME type, SQLAlchemy does not recognize the type and emits a warning:
Did not recognize type 'SYSNAME' of column 'name'
The column is then reflected as NullType, which can break downstream operations such as type genericization or DDL generation.
Observed behavior
- Warning is emitted:
Did not recognize type 'SYSNAME' of column 'name'
- Column is reflected as
NullType
Expected behavior
SYSNAME should be recognized by the MSSQL dialect and mapped appropriately (it is a built-in alias for NVARCHAR(128)), so that:
- no warning is emitted
- reflection produces a usable SQLAlchemy type (not
NullType)
Notes
SYSNAME is a built-in SQL Server type commonly used in system objects and can also be used in user-defined tables.
- This issue affects standard reflection workflows and can lead to failures when performing operations like
.as_generic() or create_all() on reflected metadata.
Optional link from https://docs.sqlalchemy.org which documents the behavior that is expected
No response
SQLAlchemy Version in Use
2.0.42
DBAPI (i.e. the database driver)
pyodbc
Database Vendor and Major Version
Microsoft SQL Server (tested on SQL Server 2022)
Python Version
3.13.11
Operating system
Windows
To Reproduce
from sqlalchemy import create_engine, Table, MetaData, Column
from sqlalchemy.types import UserDefinedType
engine = create_engine(
"mssql+pyodbc://scott:tiger@localhost/test?"
"driver=ODBC+Driver+18+for+SQL+Server&TrustServerCertificate=yes"
)
class SYSNAME(UserDefinedType):
cache_ok = True
def get_col_spec(self, **kw):
return "SYSNAME"
with engine.connect() as conn:
metadata = MetaData()
t = Table("test_sysname", metadata, Column("name", SYSNAME))
t.create(conn)
# reflection
Table("test_sysname", MetaData(), autoload_with=conn)
Error
SAWarning: Did not recognize type 'SYSNAME' of column 'name'
Additional context
No response
Describe the bug
Problem
When reflecting a SQL Server table that uses the built-in
SYSNAMEtype, SQLAlchemy does not recognize the type and emits a warning:Did not recognize type 'SYSNAME' of column 'name'
The column is then reflected as
NullType, which can break downstream operations such as type genericization or DDL generation.Observed behavior
Did not recognize type 'SYSNAME' of column 'name'
NullTypeExpected behavior
SYSNAMEshould be recognized by the MSSQL dialect and mapped appropriately (it is a built-in alias for NVARCHAR(128)), so that:NullType)Notes
SYSNAMEis a built-in SQL Server type commonly used in system objects and can also be used in user-defined tables..as_generic()orcreate_all()on reflected metadata.Optional link from https://docs.sqlalchemy.org which documents the behavior that is expected
No response
SQLAlchemy Version in Use
2.0.42
DBAPI (i.e. the database driver)
pyodbc
Database Vendor and Major Version
Microsoft SQL Server (tested on SQL Server 2022)
Python Version
3.13.11
Operating system
Windows
To Reproduce
Error
Additional context
No response