SQLAlchemy name and ambiguous column name

I had a good google search, but I can not find the answer to this error in my case.

I do not do any joins, Im literally just trying to get everything from this table.

All other queries work fine, but this seems to mess up this error:

InvalidRequestError: Ambiguous column name 'INMPTL_WIW_BATAM_STG.pers_no' in result set! try 'use_labels' option on select statement. 

Model:

  batamStg = sa.Table("INMPTL_WIW_BATAM_STG", meta.metadata, sa.Column("PERS_NO", sa.types.String(),primary_key=True), sa.Column("FIRST_NAME", sa.types.String()), sa.Column("LAST_NAME", sa.types.String()), sa.Column("KNOWN_AS", sa.types.String()), sa.Column("JOB_TITLE", sa.types.String()), sa.Column("MANAGER_NAME", sa.types.String()), sa.Column("MANAGER_ID", sa.types.String()), sa.Column("MANAGER_COST", sa.types.String()), autoload=True, autoload_with=engine) 

View:

 btm = meta.Session.query(model.BatamStaging).all(); 

There is only one column named Pers_no, and all primary keys are unique.

The same error occurs if I try to set LAST_NAME as the primary key.

Has anyone else had this problem?

+4
source share
1 answer

My hypothesis would be case-sensitive column names when overriding columns that are reflected using autoload=True . To check, comment out all the column definitions and leave autoload=True . Then do the opposite.

For more information, see Reflecting Database Objects - Overriding Reflected Columns in SA Documentation.

+4
source

Source: https://habr.com/ru/post/1381107/


All Articles