Re: [sqlalchemy] How do I access a column that is the result of an outerjoined subquery?

2022-07-10 Thread Mike Bayer
well you can do `select('*')` if you want but if you want the rows interpreted as Entry objects and not individual column objects you need to tell that to the program. select * at the moment works more easily with a core execution, like this: query = ( select('*').select_from(Entry)

Re: [sqlalchemy] How do I access a column that is the result of an outerjoined subquery?

2022-07-10 Thread Montana Burr
I see, thank you for the assistance. Doing stuff like this would be a LOT easier if there was an equivalent to "SELECT *" On Sunday, July 10, 2022 at 10:54:19 AM UTC-6 Mike Bayer wrote: > well your final select() is only against Entry, you don't have the daily > expected calories part in the

Re: [sqlalchemy] How do I access a column that is the result of an outerjoined subquery?

2022-07-10 Thread Mike Bayer
well your final select() is only against Entry, you don't have the daily expected calories part in the list of columns you are expecting. Also, your Entry class has no attribute called daily_calories_less_than_expected on it directly. there's two ways to get the data you want, one is to

Re: [sqlalchemy] How do I access a column that is the result of an outerjoined subquery?

2022-07-10 Thread Montana Burr
I suppose adding the "for" loop may be unnecessary. Simply change print(entry) in the s.scalars loop to print(entry.daily_calories_less_than_expected) and you'll (hopefully) receive a similar error: "AttributeError: 'Entry' object has no attribute 'daily_calories_less_than_expected'" On

Re: [sqlalchemy] How do I access a column that is the result of an outerjoined subquery?

2022-07-10 Thread Montana Burr
Thank you, Mike, and apologies for not providing a stack trace or MCVE of my own - I assumed the code I did provide was sufficient. So, take your program and add for entry in s.execute(query): print(entry.daily_calories_less_than_expected) to the bottom. This represents what I'm trying to

Re: [sqlalchemy] How do I access a column that is the result of an outerjoined subquery?

2022-07-10 Thread Mike Bayer
I've converted your fragments into a full MCVE and it runs fine, no error is generated. would need to see a stack trace. Try out the program below also. import datetime from sqlalchemy import Column from sqlalchemy import create_engine from sqlalchemy import Date from sqlalchemy import

[sqlalchemy] How do I access a column that is the result of an outerjoined subquery?

2022-07-09 Thread Montana Burr
Hi folks! I have a rather complicated SQL query to perform. I kind of know how I would do it in SQL and am looking to port it to SQLAlchemy. I have these ORM classes: class User(Base): __tablename__ = "Users" id = Column(Integer, primary_key=True) username = Column(String)