'Join only subset of columns with sqlalchemy core
Is there a clean way to join two tables but only select a subset of the joined table's columns?
e.g.
join_query = table_a.join(table_b, columns=[table_b.c.column_a, table_b.c.column_b])
I'm trying to avoid using select since I would have to list dozens of needed columns from table_a, but I want only a couple columns from column b.
Solution 1:[1]
Stumbled upon the way to do it, select can take either specific columns or full table references as args, so the answer would be
join_query = table_a.join(table_b).select(table_a, table_b.c.column_a, table_b.column_b)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
