[sqlalchemy] Re: anyone have an improved WindowedRangeQuery ?

2014-08-11 Thread Richard Matsen
Try basing the interval query on a correlated subquery, so instead of q = session.query( column, func.row_number().\ over(order_by=column).\ label('rownum') ).\ from_self(column)

Re: [sqlalchemy] anyone have an improved WindowedRangeQuery ?

2014-08-11 Thread Richard Matsen
Try basing the interval query on a correlated subquery, so instead of q = session.query( column, func.row_number().\ over(order_by=column).\ label('rownum') ).\ from_self(column)

Re: [sqlalchemy] anyone have an improved WindowedRangeQuery ?

2014-08-11 Thread Richard Matsen
Can do one better by just passing the filter expression. table_filter = Widget.id 5000 passing table_filter as an optional parameter to column_windows, the interval query becomes q = session.query( column, func.row_number().\

Re: [sqlalchemy] Help producing query, making use of nested joins

2014-08-11 Thread Michael Bayer
For nesting the joins you have to use the join() construct manually, your example is pretty verbose there, here's a shorter example.Note that SQLAlchemy has two join() functions - one is sqlalchemy.sql.join, the other is sqlalchemy.orm.join. The main thing you get from orm.join is that you

Re: [sqlalchemy] Use a string or reference in ForeignKey?

2014-08-11 Thread Michael Bayer
On Aug 10, 2014, at 2:52 PM, alchemy1 veerukrish...@hotmail.com wrote: I see that in ForeignKey I can use either a string or reference, so ForeignKey(MyModel.id) or ForeignKey('my_model.id'). Any advantage to using one or the other? What's the recommended approach? whichever one is more

Re: [sqlalchemy] self-referential relationship and aliases

2014-08-11 Thread dweitzenfeld
I've got the expression part of the hybrid properties working now, using an alias: @friend_code_usage_count.expression def friend_code_usage_count(cls): alias = aliased(AffinionCode) return select([func.count(alias.Rtid)]). \ where(alias.PromoCode ==

Re: [sqlalchemy] self-referential relationship and aliases

2014-08-11 Thread dweitzenfeld
I do have a follow up, actually. If I wanted to make friend_code_usage_count a column property so that it was always loaded with the object, how would I do that? It doesn't look like I can add alias = aliased(AffinionCode) within the class definition. Where/how would I define the alias?

Re: [sqlalchemy] self-referential relationship and aliases

2014-08-11 Thread Mike Bayer
For a fancy column_property like that you likely need to define it after the fact and attach it to the class. There's some new features I have in the works for 1.0 to make that easier. The general idea is: class MyClass(Base): # ... alias = aliased(MyClass) stmt =

Re: [sqlalchemy] self-referential relationship and aliases

2014-08-11 Thread dweitzenfeld
cool, thanks again. On Monday, August 11, 2014 1:19:30 PM UTC-5, Michael Bayer wrote: For a fancy column_property like that you likely need to define it after the fact and attach it to the class. There's some new features I have in the works for 1.0 to make that easier. The general

[sqlalchemy] Trying to get tables to be created by unit tests

2014-08-11 Thread alchemy1
I have combined several examples I've found to try to get the 'transactional-style' of unit tests to work, where you roll back the database after each test. However when I run this, the test fails when trying to insert the object with DBSession.add, complaining that the tables don't exist. I

Re: [sqlalchemy] Trying to get tables to be created by unit tests

2014-08-11 Thread Mike Bayer
On 08/11/2014 04:37 PM, alchemy1 wrote: I have combined several examples I've found to try to get the 'transactional-style' of unit tests to work, where you roll back the database after each test. However when I run this, the test fails when trying to insert the object with DBSession.add,