Re: [sqlalchemy] Implicit join condition

2016-07-13 Thread Mike Bayer
On 07/13/2016 02:22 PM, Seth P wrote: That works! Obviously I need to know that the joining field is called a_id, and I can live with that, since in practice it's uniform. But I'm just curious if there's an automated way to figure out which entity/column is related to A. (There could be more

Re: [sqlalchemy] Implicit join condition

2016-07-13 Thread Seth P
That works! Obviously I need to know that the joining field is called a_id, and I can live with that, since in practice it's uniform. But I'm just curious if there's an automated way to figure out which entity/column is related to A. (There could be more than one entity in q, though just one

Re: [sqlalchemy] Implicit join condition

2016-07-13 Thread Mike Bayer
On 07/13/2016 01:04 PM, Seth P wrote: Thank you, as always, for the quick and detailed response. With the join to the subquery that's on func.max(A.id), once you use that function, the column loses it's "A.id-ness", because SQLA doesn't know anything about func.max() and for all

Re: [sqlalchemy] Implicit join condition

2016-07-13 Thread Seth P
Thank you, as always, for the quick and detailed response. With the join to the subquery that's on func.max(A.id), once you use > that function, the column loses it's "A.id-ness", because SQLA doesn't > know anything about func.max() and for all it knows it could be turning > it into anything.

Re: [sqlalchemy] Implicit join condition

2016-07-13 Thread Mike Bayer
On 07/13/2016 02:29 AM, Seth P wrote: [Apologies for posting an incomplete version of this post earlier. Please ignore it.] If B has a ForeignKey (and relationship) to A (e.g. B.a_id -> A.id), then I can write query(B.b_num).join(A) without specifying the condition, and SQLAlchemy will figure

Re: [sqlalchemy] Recursive CTE failing with (pysqlite2.dbapi2.OperationalError) no such table

2016-07-13 Thread Jonathan Underwood
On Wednesday, July 13, 2016 at 4:25:24 PM UTC+1, Jonathan Vanasco wrote: > > > > On Wednesday, July 13, 2016 at 11:01:08 AM UTC-4, Jonathan Underwood wrote: > > Thanks - you're right. That's weird though, as it contradicts the >> documentation. Anyway, I've found it all works as expected,

[sqlalchemy] Re: Implicit join condition

2016-07-13 Thread Seth P
Actually, taking a closer look, the sql generated for query 5 doesn't look correct (or at least not what I want), since it isn't joining max_a_id with anything. On Wednesday, July 13, 2016 at 2:29:34 AM UTC-4, Seth P wrote: > > [Apologies for posting an incomplete version of this post earlier.

Re: [sqlalchemy] Recursive CTE failing with (pysqlite2.dbapi2.OperationalError) no such table

2016-07-13 Thread Jonathan Underwood
On Wednesday, July 13, 2016 at 4:01:08 PM UTC+1, Jonathan Underwood wrote: > > > > On Wednesday, July 13, 2016 at 2:35:06 PM UTC+1, Антонио Антуан wrote: >> >> `cteq_alias.union_all(...` >> >> Also, you do not need to create cteq_alias, you can use cteq, like in >> your query, but you have to

Re: [sqlalchemy] Recursive CTE failing with (pysqlite2.dbapi2.OperationalError) no such table

2016-07-13 Thread Jonathan Vanasco
On Wednesday, July 13, 2016 at 11:01:08 AM UTC-4, Jonathan Underwood wrote: Thanks - you're right. That's weird though, as it contradicts the > documentation. Anyway, I've found it all works as expected, simply by not > bothering to create the aliases: > I think I've run into this problem

Re: [sqlalchemy] Recursive CTE failing with (pysqlite2.dbapi2.OperationalError) no such table

2016-07-13 Thread Jonathan Underwood
On Wednesday, July 13, 2016 at 2:35:06 PM UTC+1, Антонио Антуан wrote: > > `cteq_alias.union_all(...` > > Also, you do not need to create cteq_alias, you can use cteq, like in > your query, but you have to replace cteq_alias.c.id with cteq.c.id > > Thanks - you're right. That's weird though, as

Re: [sqlalchemy] Recursive CTE failing with (pysqlite2.dbapi2.OperationalError) no such table

2016-07-13 Thread Антонио Антуан
`cteq_alias.union_all(...` Also, you do not need to create cteq_alias, you can use cteq, like in your query, but you have to replace cteq_alias.c.id with cteq.c.id ср, 13 июл. 2016 г. в 15:20, Jonathan Underwood < jonathan.underw...@gmail.com>: > Hi, > > I am struggling to get a simple

[sqlalchemy] Recursive CTE failing with (pysqlite2.dbapi2.OperationalError) no such table

2016-07-13 Thread Jonathan Underwood
Hi, I am struggling to get a simple recursive CTE query to work with sqlalchemy 1.0.14, sqlite backend (3.8.10.2) and pysqlite 2.8.2, python 2.7.12. Below is a reproducer: from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, String from sqlalchemy import orm

Re: [sqlalchemy] Re: Specify query_cls for the one query

2016-07-13 Thread Антонио Антуан
Amazing! :) Big thanks. ср, 13 июл. 2016 г. в 12:59, Simon King : > OK, I have to admit that I haven't fully understood the details of > what you are doing. However, it sounds like you are implementing > horizontal sharding, which SQLAlchemy has a bit of support for: > >

Re: [sqlalchemy] Re: Specify query_cls for the one query

2016-07-13 Thread Simon King
OK, I have to admit that I haven't fully understood the details of what you are doing. However, it sounds like you are implementing horizontal sharding, which SQLAlchemy has a bit of support for: http://docs.sqlalchemy.org/en/latest/orm/extensions/horizontal_shard.html

[sqlalchemy] Use filter in query, then use func.concat update invalid

2016-07-13 Thread aogooc
examples: from sqlalchemy import func project_list = ['platform', 'vip'] content = 'this is test text' r = session.query(Project).filter(Project.name.in_(project_list)) r.update({'change_log': func.concat(Project.change_log, content)}, synchronize_session='fetch') session.commit()

[sqlalchemy] Implicit join condition

2016-07-13 Thread Seth P
[Apologies for posting an incomplete version of this post earlier. Please ignore it.] If B has a ForeignKey (and relationship) to A (e.g. B.a_id -> A.id), then I can write query(B.b_num).join(A) without specifying the condition, and SQLAlchemy will figure out the join automatically. [See query