Re: [sqlalchemy] correlated subquery as column_property can't be queried independently?

2021-11-10 Thread Mike Bayer
if you use 1.4 /2.0 querying style you can call upon the scalars() method of the result result = session.execute(select(MyClass.attr)) elements = result.scalars().all() or result = session.scalars(select(...)) elements = result.all() otherwise you can just iterate like this: elements = [e

Re: [sqlalchemy] correlated subquery as column_property can't be queried independently?

2021-11-10 Thread niuji...@gmail.com
This is very helpful. How to return a list of scalar values in this case? Now the query returns a list of tuples, and each tuple only has one value, which is what actually needed. Is there a parameter to return a series of scalar value like this? On Wednesday, November 10, 2021 at 12:05:27 PM

Re: [sqlalchemy] correlated subquery as column_property can't be queried independently?

2021-11-10 Thread Mike Bayer
it has to do with how SQLAlchemy determines the FROM list in a select() statement. if you say select(table.c.id), it knows that "table" is the thing to select "from". however, if you say select(select(...).correlate(...).scalar_subquery()), that's assuming it's a SELECT from a scalar

Re: [sqlalchemy] correlated subquery as column_property can't be queried independently?

2021-11-10 Thread niuji...@gmail.com
This works! Could you explain a little about this differences by using select_from here? I think this is very important and useful, really want to learn it right. On Wednesday, November 10, 2021 at 5:55:44 AM UTC-8 Mike Bayer wrote: > try calling: > > query(C.symbol_from_a).select_from(C) > >

Re: [sqlalchemy] correlated subquery as column_property can't be queried independently?

2021-11-10 Thread Mike Bayer
try calling: query(C.symbol_from_a).select_from(C) On Wed, Nov 10, 2021, at 4:50 AM, niuji...@gmail.com wrote: > class A(Base): > primary_id = Column(Integer, prirmary_key=True) > some_A_marker = Column(String) > > class B(Base): > primary_id = Column(Integer, primary_key=True) >

[sqlalchemy] correlated subquery as column_property can't be queried independently?

2021-11-10 Thread niuji...@gmail.com
class A(Base): primary_id = Column(Integer, prirmary_key=True) some_A_marker = Column(String) class B(Base): primary_id = Column(Integer, primary_key=True) referencing_A_id = Column(Integer, ForeignKey(A.primary_id)) class C(Base): primary_id = Column(Integer,