If you import col
from sqlmodel
and wrap the relevant columns with col
, the type errors should disappear, at least for the ones in your example:
from sqlmodel import Field, SQLModel, select, col
class TableX(SQLModel, table=True):
id: int | None = Field(default=None, primary_key=True)
x: str
class TableY(SQLModel, table=True):
id: int
y: str
z: str
query = (
select(TableX)
.join(TableY, col(TableX.id) == col(TableY.id))
.where(col(TableY.z).in_(["A", "B", "C"]))
)
See: