• Как использовать union и join в одном SQLAlchemy запросе?

    drew_dru
    @drew_dru Автор вопроса
    При следующем query2 при объединении падает с ошибкой:

    All selectables passed to CompoundSelect must have identical numbers of columns; select #1 has 28 columns, select #2 has 31

    query2
    query2 = self.session.query(\
                    sql.null().label('id_streets_id_np'),\
                    sql.null().label('id_streets_id_street'),\
                    sql.null().label('id_streets_name_street'),\
                    sql.null().label('id_streets_type_street'),\
                    ID_Streets_history, ID_Nps, Modify_reason)
                query2 = outerjoin(query2, ID_Nps, ID_Nps.id_np == ID_Streets_history.id_np)
                query2 = outerjoin(query2, Modify_reason, text(\
                        '(ID_Streets_history.code_reason=Modify_reason.code_reason '\
                        'AND ID_Streets_history.code_detail=Modify_reason.code_detail)'))


    Но при генерации query2 количество колонок не изменилось.
    Сгенерированный query2 перед объединением
    (SELECT NULL AS id_streets_id_np, NULL AS id_streets_id_street, NULL AS id_streets_name_street, NULL AS id_streets_type_street, id_streets_history.id_np AS id_streets_history_id_np, id_streets_history.id_street AS id_streets_history_id_street, id_streets_history.id_row AS id_streets_history_id_row, id_streets_history.name_street AS id_streets_history_name_street, id_streets_history.type_street AS id_streets_history_type_street, id_streets_history.code_reason AS id_streets_history_code_reason, id_streets_history.code_detail AS id_streets_history_code_detail, id_streets_history.creater AS id_streets_history_creater, id_streets_history.createddate AS id_streets_history_createddate, id_streets_history.updater AS id_streets_history_updater, id_streets_history.updateddate AS id_streets_history_updateddate, id_streets_history.recordcomment AS id_streets_history_recordcomment, id_streets_history.sourcecomment AS id_streets_history_sourcecomment, id_nps.id_region AS id_nps_id_region, id_nps.id_atu AS id_nps_id_atu, id_nps.id_selsov AS id_nps_id_selsov, id_nps.id_np AS id_nps_id_np, id_nps.name_np AS id_nps_name_np, id_nps.type_np AS id_nps_type_np, id_nps.okato AS id_nps_okato, id_nps.oktmo AS id_nps_oktmo, modify_reason.code_reason AS modify_reason_code_reason, modify_reason.code_detail AS modify_reason_code_detail, modify_reason.comment_reason AS modify_reason_comment_reason 
    FROM id_streets_history, id_nps, modify_reason) LEFT OUTER JOIN id_nps ON id_nps.id_np = id_streets_history.id_np LEFT OUTER JOIN modify_reason ON (ID_Streets_history.code_reason=Modify_reason.code_reason AND ID_Streets_history.code_detail=Modify_reason.code_detail)

  • Как использовать union и join в одном SQLAlchemy запросе?

    drew_dru
    @drew_dru Автор вопроса
    UPDATE:
    Так session.query обрубает join'ы в запросе:
    spoiler
    from sqlalchemy import outerjoin
    ...
    query_test = self.session.query(\
                    sql.null().label('id_streets_id_np'),\
                    sql.null().label('id_streets_id_street'),\
                    sql.null().label('id_streets_name_street'),\
                    sql.null().label('id_streets_type_street'),\
                    ID_Streets_history,\
                    outerjoin(ID_Streets_history, ID_Nps, ID_Nps.id_np == ID_Streets_history.id_np),\
                    outerjoin(ID_Streets_history, Modify_reason, text(\
                        '(ID_Streets_history.code_reason=Modify_reason.code_reason '\
                        'AND ID_Streets_history.code_detail=Modify_reason.code_detail)')))
  • Как отобразить изображение в qml?

    drew_dru
    @drew_dru Автор вопроса
    Спасибо за помощь. Разобрался:
    Нужно было перед указанием пути добавить "file:"