Re: [sqlalchemy] Re: Unable to reference label in subquery at top level of query

2019-02-07 Thread Ian Miller
:facepalm: i should have seen that much sooner. Thank you so much for your help. No longer need to do any of that crazy stuff I attempted! On Thursday, February 7, 2019 at 5:13:41 PM UTC-5, Mike Bayer wrote: > > On Thu, Feb 7, 2019 at 2:49 PM Ian Miller > wrote: > > > > The reason why I

Re: [sqlalchemy] Compiling to Postgres VALUES clause with bindparam

2019-02-07 Thread Mike Bayer
On Thu, Feb 7, 2019 at 3:59 PM Martin Stein wrote: > > We are using Postgres, the baked extension and have code along these lines: > > query = bakery( > lambda s: s.query(Item) >.filter(Item.parent_id.op('IN')(bindparam('parent_ids'))) > > > result =

Re: [sqlalchemy] Re: Unable to reference label in subquery at top level of query

2019-02-07 Thread Mike Bayer
On Thu, Feb 7, 2019 at 2:49 PM Ian Miller wrote: > > The reason why I iterated over .c._all_columns was because it shows the > references to the 2 "metadata_value" columns, whereas selectable.c only > references 1. so that's a sign that you need to apply labels to these columns because they

Re: [sqlalchemy] Re: Unable to reference label in subquery at top level of query

2019-02-07 Thread Ian Miller
The reason why I iterated over .c._all_columns was because it shows the references to the 2 "metadata_value" columns, whereas selectable.c only references 1. For example, selectable.c shows the following: (Pdb++) list(query.c) [Column('metadata_value', VARCHAR(length=255), table=),

Re: [sqlalchemy] Re: Unable to reference label in subquery at top level of query

2019-02-07 Thread Ian Miller
The reason why I iterated over .c._all_columns was because it shows the references to the 2 "metadata_value" columns, whereas selectable.c only references 1. For example, selectable.c shows the following: (Pdb++) list(query.c) [Column('metadata_value', VARCHAR(length=255), table=),

Re: [sqlalchemy] Re: Unable to reference label in subquery at top level of query

2019-02-07 Thread Mike Bayer
just as a note, don't access .c._all_columns, just iterate over selectable.c On Thu, Feb 7, 2019 at 10:45 AM Ian Miller wrote: > > Hello Mike, > > Thank you for your response! I have currently constructed the ORM > implementation that you suggested in your response. Here's the code: > > def

[sqlalchemy] Re: Unable to reference label in subquery at top level of query

2019-02-07 Thread Ian Miller
Ah - this occurs because the non-metadata_value columns added in from "query .c._all_columns" are still referencing the original query. I need to figure out how to rebuild those columns as well so that they correctly reference the clauses in the new query. On Tuesday, February 5, 2019 at

[sqlalchemy] Re: Unable to reference label in subquery at top level of query

2019-02-07 Thread Ian Miller
Hello Mike, Thank you for your response! I have currently constructed the ORM implementation that you suggested in your response. Here's the code: def _rebuild_non_interval_query_for_group_by(self, session, query): from sqlalchemy import table, column, select from sqlalchemy.orm import