Column alias created by SQLAlchemy is exeeding max column length of db2.

445 views
Skip to first unread message

Beeno

unread,
Jun 24, 2009, 8:49:10 AM6/24/09
to sqlalchemy
Hello

Sqlalchemy appears to be aliasing each column in a SELECT statement as
a concatenation of the schema, table name and column name. The
resulting alias exceeds DB2's 30 character limit for a column.

For example:

If the name of the schema was 'myshemaname', the table was called
'mytablename' and the column was appropriately named 'mycolumnname'
the resuling alias of the column would be
myschemaname_mytablename_mycolumnname and the following DB2 SQL
exception will be generated:

sqlalchemy.exceptions.ProgrammingError: (ProgrammingError)
ibm_db_dbi::ProgrammingError: [IBM][CLI Driver][DB2/AIX64] SQL0107N
The name "myschemaname_mytablename_mycolumnname" is too long. The
maximum length is "30". SQLSTATE=4

Is the any workaround for this?

Is there anyway for force Sqlalchemy to use only the colum name when
creating an alias?

Beeno

unread,
Jun 24, 2009, 8:55:39 AM6/24/09
to sqlalchemy

Michael Bayer

unread,
Jun 24, 2009, 10:25:09 AM6/24/09
to sqlal...@googlegroups.com

this is technically a bug in the DB2 dialect as they should be setting the
"max_identifier_length" attribute correctly on their dialect. You can
set it manually:

engine = create_engine(...)
engine.dialect.max_identifier_length = 30


Yap Sok Ann

unread,
Apr 21, 2012, 7:04:07 PM4/21/12
to sqlal...@googlegroups.com
Sorry to dig up an old thread. On DB2 for z/OS, the identifier length limit is 30 for column and column alias, and 128 for almost everything else:


I can set `label_length = 30` to apply the limit for column alias. What would be the best way to apply the limit for column only, without affecting table, constraint, etc?

Michael Bayer

unread,
Apr 21, 2012, 8:50:04 PM4/21/12
to sqlal...@googlegroups.com
On Apr 21, 2012, at 7:04 PM, Yap Sok Ann wrote:


Sorry to dig up an old thread. On DB2 for z/OS, the identifier length limit is 30 for column and column alias, and 128 for almost everything else:


I can set `label_length = 30` to apply the limit for column alias. What would be the best way to apply the limit for column only, without affecting table, constraint, etc?

we'd have to modify the library to support this feature.


Reply all
Reply to author
Forward
0 new messages