Re: [sqlalchemy] Limiting query with custom order_by and eagerload

2011-06-07 Thread Michael Bayer
this is ticket 2188: http://www.sqlalchemy.org/trac/ticket/2188 The issue involves excessive digging into the column expressions of the order by, when it attempts to place those columns into the nested query. This step is necessary for many tests where the columns need to be SELECTed on the in

Re: [sqlalchemy] Limiting query with custom order_by and eagerload

2011-06-07 Thread Michael Bayer
sorry, either: results = session.query(Book).options( orm.undefer(Book.num_purchased), orm.contains_eager('purchases') ).order_by("calculated_books_num_purchased").\ limit(50).from_

Re: [sqlalchemy] Limiting query with custom order_by and eagerload

2011-06-07 Thread Michael Bayer
you can do it manually as the combination of automatic joins and ordering by subqueries seems to get tripped up (its a bug, but not sure of the nature of it) results = session.query(Book).options( orm.undefer(Book.num_purchased), or

Re: [sqlalchemy] sqlalchemy filter by count problem

2011-06-07 Thread Mike Conley
Not sure how you get 2 queries, but this seems like it gives right answer. class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) items = relationship('Item') class Item(Base): __tablename__ = 'items' id = Column(Integer, pr

[sqlalchemy] Limiting query with custom order_by and eagerload

2011-06-07 Thread Yoann Roman
I ran into a problem with a rather unique query on SA 0.6.5 (reproducible on 0.7.1). The query eagerloads a collection, undefers a scalar-select column, orders on the latter, and applies a limit/ offset. To order by a scalar-select column without executing the subquery again, I have to apply a cust

[sqlalchemy] sqlalchemy filter by count problem

2011-06-07 Thread cio...@gmail.com
I have a select with a count on it. Count row is taken from another related table so I can see how many items a user has. I want to filter the results to select only those with items more than 5 let's say. Sqlalchemy generates 2 queries for this. Placing a 'having' filter gives an error but lookin

Re: [sqlalchemy] get_history not returning as expected

2011-06-07 Thread Michael Bayer
On Jun 7, 2011, at 1:23 PM, Sebastian Elsner wrote: > Hello, > > using Python 2.6 and SA 0.6.6. Please see the example below. I want to get > the History of a relationship attribute, but whatever I pass to the "passive" > argument, I never get the "deleted version" of the object, only the > P

[sqlalchemy] get_history not returning as expected

2011-06-07 Thread Sebastian Elsner
Hello, using Python 2.6 and SA 0.6.6. Please see the example below. I want to get the History of a relationship attribute, but whatever I pass to the "passive" argument, I never get the "deleted version" of the object, only the PASSIVE_NO_RESULT symbol (if I understand correctly, I would not

Re: [sqlalchemy] .count()'ing with limiting query.

2011-06-07 Thread Michael Bayer
On Jun 7, 2011, at 8:57 AM, Filip Zyzniewski - Tefnet wrote: > # this line: > print BillGates.subordinates.count() > # raises: > # Traceback (most recent call last): > # File "count_problem.py", line 60, in > # print BillGates.subordinates.count() > # File > "/home/filip/tefnet/teferp/w

Re: [sqlalchemy] AttributeError (_inserted_primary_key) when retrieving ids of 'bulk insert'

2011-06-07 Thread Michael Bayer
On Jun 7, 2011, at 6:03 AM, Felix Wolfsteller wrote: > Hi, > > I try to insert a big number of of rows to a table and want to receive the > ids > that were assigned to these (new) rows. > If i insert a single row, it works as expected, but with multiple rows I run > into an error: > Attribute

Re: [sqlalchemy] Concurrent upsert problem with session.merge()

2011-06-07 Thread A.M.
On Jun 7, 2011, at 7:17 AM, Vlad K. wrote: > > Hi all! > > > I have a daily stats table with the date as primary key. Currently the date > is string in the MMDD format, but I'll probably port it to a Date type > for easier statistical analysis. Other cols are various counters that get >

Re: [sqlalchemy] mapping stored procedures results to an object

2011-06-07 Thread Michael Bayer
not that I'm aware of but its something I consider often. the closest right now is if the SP is callable as in func.foo(), you can map to func.foo(). http://www.sqlalchemy.org/trac/wiki/07Migration#Non-Table-derivedconstructscanbemapped but this considers the function to be like a "view", which

[sqlalchemy] Concurrent upsert problem with session.merge()

2011-06-07 Thread Vlad K.
Hi all! I have a daily stats table with the date as primary key. Currently the date is string in the MMDD format, but I'll probably port it to a Date type for easier statistical analysis. Other cols are various counters that get incremented in various situations. My problem is that I n

[sqlalchemy] Re: porting GeoAlchemy to 0.7

2011-06-07 Thread Eric Lemoine
Here's the code I've come up with: class GeometryDDL(object): try: from sqlalchemy import event except ImportError: # SQLAlchemy 0.6 use_event = False columns_attribute = '_columns' else: # SQLALchemy 0.7 use_event = True columns_

[sqlalchemy] .count()'ing with limiting query.

2011-06-07 Thread Filip Zyzniewski - Tefnet
Hi everybody, After switching from SQLAlchemy 0.6.5 to 0.7.0 we have observed a problem with such an example code: (copy at http://ideone.com/WB36Y) == # Fails with Python-2.7.1 and SQLAlchemy-0.7.0 # import sqlalchemy import sqlalchem

[sqlalchemy] AttributeError (_inserted_primary_key) when retrieving ids of 'bulk insert'

2011-06-07 Thread Felix Wolfsteller
Hi, I try to insert a big number of of rows to a table and want to receive the ids that were assigned to these (new) rows. If i insert a single row, it works as expected, but with multiple rows I run into an error: AttributeError: 'DefaultExecutionContext' object has no attribute '_inserted_pri

[sqlalchemy] mapping stored procedures results to an object

2011-06-07 Thread Chris Withers
Hi All, Are there any example knocking about of mapping the results of a MySQL stored procedure to an object? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- You received this message because you are subscrib

[sqlalchemy] Re: Secondary tables and deleting

2011-06-07 Thread Geoff
On Jun 7, 12:42 am, Michael Bayer wrote: > > Below is a short test, can you figure out what you might be doing differently > ? [snip] Michael, thanks very much. The database I'm looking at is my test database for the application I'm developing and it gets used and abused quite often and it's en