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
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
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
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)
>
>
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)
>
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,