想要返回行号而不是IDX。
在Python 3.6.5中,使用SQLAlchemy 1.2.15和aws rds,可以实现该功能。
在Python 3.6.5中,使用SQLAlchemy 1.2.15和aws rds,可以实现该功能。
query = session.query(product)
row_number_column = func.row_number().over(order_by='IDX').label('row_num')
query = query.add_column(row_number_column)
运行query.all()时返回语法错误。
sqlalchemy.exc.ProgrammingError: (pymysql.err.ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(ORDER BY product.
IDX
) ASROW_NUM
\nFROM product' at line 1") [SQL: 'SELECT product.IDX
ASproduct_IDX
, product.PD_SERIAL
ASproduct_PD_SERIAL
, product.PD_COUNT
ASproduct_PD_COUNT
, /.../ product.UPDATE_TIME
ASproduct_UPDATE_TIME
, row_number() OVER (ORDER BY product.IDX
) ASROW_NUM
\nFROM product'] (Background on this error at: http://sqlalche.me/e/f405)