Re: [sqlalchemy] Making a unique key from two non-unique fields with reflected database?

2022-07-10 Thread Carl Brewer
On 11/07/2022 1:19 am, Mike Bayer wrote: background on mapping ORM classes to reflected tables is at https://docs.sqlalchemy.org/en/14/orm/declarative_tables.html#mapping-declaratively-with-reflected-tables

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

Re: [sqlalchemy] Making a unique key from two non-unique fields with reflected database?

2022-07-10 Thread Mike Bayer
background on mapping ORM classes to reflected tables is at https://docs.sqlalchemy.org/en/14/orm/declarative_tables.html#mapping-declaratively-with-reflected-tables and there are three general methods depending on your needs. DeferredReflection is oriented towards explicit class setup, and

[sqlalchemy] Making a unique key from two non-unique fields with reflected database?

2022-07-10 Thread Carl Brewer
I'm reflecting a table into the ORM, that has no defined unique key, but has two fields that when combined are unique - it's MySQL, but that shouldn't matter. Eg: int userID and int groupId are non-unique, but when combined they are. Can anyone point me at a simple example of how to do