Hi, I've been using SQLAlchemy for the last couple of weeks. I'll definitely call myself a beginner so I apologize if I'm missing something obvious with this question :)
I'm working with a database where there is data split across tables with the exact same structure, so there are cases where I need to query more than one table and filter by the same criteria. Looking around in the documentation I read about Concrete Table Inheritance and thought that could help me in this case. Well, it almost did :) I might be missing something obvious, but if we take the example provided: http://docs.sqlalchemy.org/en/rel_0_7/orm/inheritance.html#concrete-table-inheritance And perform a query such as: session.query(Employee).filter(Employee.name=='test') It will apply the name filter after the union is done: SELECT pjoin.employee_id AS pjoin_employee_id, pjoin.name AS pjoin_name, pjoin.type AS pjoin_type, pjoin.manager_data AS pjoin_manager_data, pjoin.engineer_info AS pjoin_engineer_info FROM (SELECT employees.employee_id AS employee_id, employees.name AS name, CAST(NULL AS VARCHAR(50)) AS manager_data, CAST(NULL AS VARCHAR(50)) AS engineer_info, 'employee' AS type FROM employees UNION ALL SELECT managers.employee_id AS employee_id, managers.name AS name, managers.manager_data AS manager_data, CAST(NULL AS VARCHAR(50)) AS engineer_info, 'manager' AS type FROM managers UNION ALL SELECT engineers.employee_id AS employee_id, engineers.name AS name, CAST(NULL AS VARCHAR(50)) AS manager_data, engineers.engineer_info AS engineer_info, 'engineer' AS type FROM engineers) AS pjoin WHERE pjoin.name = :name_1 Is there a way to ask SQLAlchemy to apply the filter to each table in the inner queries? They all have a name column, and in the case of a large dataset it's helpful because it avoids loading all the rows for each table first and then applying the WHERE clause. Thanks in advance, Benjamin -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/7v3YPtbCDP0J. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.