I'm trying to query multiple tables by joining and selecting specific columns using SQLAlchemy. My query looks like this this
data = db.session.query(
TableA,
TableB,
TableC,
).filter(
TableA.id == TableB.x_id,
TableA.id2 == TableB.y_id,
TableA.id3 == TableB.z_id,
).filter(
TableA.id == TableC.id_a,
TableA.id3 == TableC.id_b,
between(TableB.date, from_date, to_date)
).distinct(
TableA.id
).select(
TableA.id,
TableA.contact,
TableB.city,
TableC.source,
TableC.name,
).all()
When I run this I get an error
AttributeError: 'BaseQuery' object has no attribute 'select'
How can I select specific columns with this query or how can it be improved? The reason for selecting specific columns is that all of these tables have 10s of the columns and returning back all columns will be slow as it will have a lot of data. I tried to move the select func to the beginning but it didn't help.