Skip to content
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

Mssql type TEXT with length #237

Open
leo-schick opened this issue Oct 28, 2022 · 2 comments
Open

Mssql type TEXT with length #237

leo-schick opened this issue Oct 28, 2022 · 2 comments

Comments

@leo-schick
Copy link

I have the following MSSQL table:

CREATE TABLE LiquidityPlanning.Parameters
(
	Id int IDENTITY(1,1) NOT NULL,
	Name nvarchar(80) NOT NULL,
	Description text NULL,
	Value int NULL,
	DefaultValue int NULL
);

This generates the following file:

from sqlalchemy import Column, Identity, Integer, MetaData, TEXT, Table, Unicode

metadata = MetaData()


t_Parameters = Table(
    'Parameters', metadata,
    Column('Id', Integer, Identity(start=1, increment=1), nullable=False),
    Column('Name', Unicode(80), nullable=False),
    Column('Description', TEXT(2147483647, 'SQL_Latin1_General_CP1_CI_AS')),
    Column('Value', Integer),
    Column('DefaultValue', Integer),
    schema='LiquidityPlanning'
)

The length of the TEXT type is not necessary. Length 2147483647 is the max length of a 4 byte integer. I my opinion, the max length should not be put into the SQLAlchemy model in this case.

@agronholm
Copy link
Owner

Does a TEXT column always have a length on SQL Server? Sqlacodegen doesn't know if the length is necessary, it just copies whatever parameters it gets from the reflected metadata.

@leo-schick
Copy link
Author

@agronholm No. TEXT by default is not limited. When you create a table, it is common to use CREATE my_table ( column_name TEXT NULL ).
The official documentation for type TEXT (and NTEXT) does not document an option to specify the length explicitly - but for varchar/nvarchar it is documented (see here).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants