Home > Software design >  How to change prefix for alias at table with declarative base
How to change prefix for alias at table with declarative base

Time:01-28

I got table like this:

class ReportImages(Base):

    __tablename__ = 'very_long_name_of_table'

    id = Column('long_column_name', Integer, primary_key=True)

And i run select from Oracle Database it raises exception:

sqlalchemy.exc.DatabaseError: (cx_Oracle.DatabaseError) ORA-00972: identifier is too long
[SQL: SELECT very_long_name_of_table.long_column_name AS very_long_name_of_table_long_column_name FROM very_long_name_of_table]

How can is set my own alias for select or not to use column aliases at all?

Select like

data = session.query(ReportImages).all()

CodePudding user response:

Solved it with setting alias before query:

        ri = aliased(ReportImages, name='ri')
        data = session.query(ri)

It works, but still interesting how i can set label styling in ReportImages class.

  •  Tags:  
  • Related