add VARCHAR, NVARCHAR placeholder types to SQL Server dialect, support first class compilation

Issue #3759 duplicate
Asher Leon Manning created an issue

At line 2523 in sqlalchemy\sql\compiler ,

text += "(%d)" % type_.length

causes a TypeError, as the '%d' expects a number, not 'max'

Comments (12)

  1. Asher Leon Manning reporter

    I encountered the bug with SQL Server 2008, but 'max' is allowed in all versions of SQL Server since 2005.

  2. Mike Bayer repo owner

    If this is SQL Server, please use sqlalchemy.dialects.mssql.VARCHAR() and don't specify a length.

  3. Asher Leon Manning reporter

    It should not be necessary to make modifications to a database to use SQLAlchemy on it.

    The error was encountered in the following code

        connectstring =  ('mssql+pyodbc:///?odbc_connect=DRIVER.....')
        title = 'table_title'
        en = sqlalchemy.create_engine(connectstring)
        md= sqlalchemy.MetaData()
        table = sqlalchemy.Table('%s' %title, md, autoload=True, autoload_with=en)
        for c in table.columns:
            print c.type
    

    If the database contains a column of type Integer(max) or Varchar(max), etc, it will throw this error.

  4. Mike Bayer repo owner

    OK nevermind, this was handled differently as part of #3504. that is, we don't leak the "max" detail into the type.

  5. Mike Bayer repo owner

    please use:

    print repr(c.type)
    

    or:

    from sqlalchemy.dialects import mssql
    print c.type.compile(dialect=mssql.dialect())
    

    until you can upgrade to 1.1.

  6. Log in to comment