0

如何在定义此代码时在 python 中加入多个表我收到错误:

class A(PresentationUnified, TableDocMixin):
    Pk = Column(BIGINT,  primary_key=True)
    tenantid = Column(BIGINT)
    auditinfo__createdate = Column(TIMESTAMP)
    auditinfo__updatedate = Column(TIMESTAMP)
    currency_code = Column(String(512))
    

    PrimaryKeyConstraint(Pk, name='pk')

    __tablename__ = 'cart_fact'
    
    def __init__(self, schema=PresentationUnified.metadata.schema):
      self.__table__.schema = schema


    def __source(self, session, schema, monetate_schema, postgres_schema, is_migration):
        Currency = "\'USD\'"
        Tenant(schema=postgres_schema)
        Cart(schema=schema)
        CurrentExchangeRate1 = None
        CurrentExchangeRate2 = None
        
        query = session.query(func.md5(func.CONVERT(literal_column('varchar'),Cart._id)
                                       + func.CONVERT(literal_column('varchar'),Cart.tenantid)).label("FC_pkey")
                              , Cart.tenantid.label("tenantid")
                              , Cart.auditinfo__createdate.label("auditinfo__createdate")
                              , Cart.auditinfo__updatedate.label("auditinfo__updatedate")
                              , func.upper(Tenant.reportingcurrencycode).label("currency_code")
                              )

        return query.join(CurrentExchangeRate1, and_(func.UPPER(Cart.currencycode) ==
                                                         func.UPPER(CurrentExchangeRate1.from_currency_code),
                                                         func.upper(CurrentExchangeRate1.to_currency_code) == Currency,
                                                         func.trunc(func.dateadd(literal_column('day'), -1, func.to_date(Cart.auditinfo__createdate,'YYYY-MM-DD HH:MI:SS')))
                                                         == func.trunc(CurrentExchangeRate1.effective_date)),isouter=True).\
                join(Tenant , Cart.tenantid == Tenant.tenantid).join \
                (CurrentExchangeRate2, and_(func.UPPER(Cart.currencycode) == func.UPPER(CurrentExchangeRate2.from_currency_code),
                                            func.upper(CurrentExchangeRate2.to_currency_code) == func.UPPER(Tenant.reportingcurrencycode) ,
                                            func.trunc(func.dateadd(literal_column('day'), -1,func.to_date(Cart.auditinfo__createdate ,'YYYY-MM-DD HH:MI:SS'))) == func.trunc(CurrentExchangeRate2.effective_date)),isouter=True)

I identify that after commenting "currency_code " column i am not getting errors but that is much needed field for my target table
4

0 回答 0