1.使用 datetime.__str__()
OperatingInstructionLog.open_time >= datetime(date.year, date.month, date.day + 1, 0, 0, 0).__str__()
2.例:
# 构建查询器
query = session.query(OperatingInstructionLog).filter(OperatingInstructionLog.type == 3).filter(not_(
or_(OperatingInstructionLog.open_time >= datetime(date.year, date.month, date.day + 1, 0, 0, 0).__str__(),
OperatingInstructionLog.close_time <= datetime(date.year, date.month, date.day, 0, 0,
0).__str__()))).order_by(
OperatingInstructionLog.open_time.asc())
# 查询
operatingInstructionLogs: list[OperatingInstructionLog] = query.all()
# 打印原生SQL
print("原生SQL:", query.statement.compile(dialect=postgresql.dialect(), compile_kwargs={"literal_binds": True}))