[sqlalchemy] Problems with scalar subquery

2011-02-23 Thread Randall Nortman
I have a somewhat nasty query problem, which I have abstracted and (partially) simplified into the following test case: - test.py - from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import scoped_session, sessionmaker, aliased, relationship from sqlalchemy import

[sqlalchemy] Re: Problems with scalar subquery

2011-02-23 Thread Randall Nortman
(that I left out in my original example) as a filter on the query, SQLAlchemy also adds table_a to the FROM of the subquery, which is also not what I want. On Feb 23, 12:08 pm, Randall Nortman wondercl...@gmail.com wrote: I have a somewhat nasty query problem, which I have abstracted and (partially

[sqlalchemy] Re: Problems with scalar subquery

2011-02-23 Thread Randall Nortman
Nevermind. I kept digging and found Query.correlate(). This code works: Session.query(TableC.id, TableC.group_key) .join(TableC.b, TableB.a) .filter(TableA.some_key == 42) .filter(TableC.sort_key == Session.query(func.max(c1.sort_key))

[sqlalchemy] Eager loading object graph

2011-02-18 Thread Randall Nortman
I have working code -- I just want to make sure I'm doing this the best way. If I have a graph of related objects, spanning numerous tables and relationships, including many-to-many, and I want to eagerly load the entire graph (rooted in some selected row or rows of one of the tables) in a single

[sqlalchemy] Re: Eager loading object graph

2011-02-18 Thread Randall Nortman
On Feb 18, 11:22 am, Michael Bayer mike...@zzzcomputing.com wrote: On Feb 18, 2011, at 11:09 AM, Randall Nortman wrote: [...] are you watching the SQL emitted when you load everything ?   in 0.7, we've made a change to contains_eager() such that what you have above will work as expected

[sqlalchemy] Re: Best way to reduce boilerplate?

2011-01-14 Thread Randall Nortman
I'm having trouble getting mixins to play nicely with __table_args__. Using the example I gave earlier in this thread: On Jan 13, 1:00 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Jan 13, 2011, at 12:11 PM, Randall Nortman wrote: [...]    namespace_id = Column(Integer, ForeignKey

[sqlalchemy] Re: Best way to reduce boilerplate?

2011-01-14 Thread Randall Nortman
On Jan 14, 1:07 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Jan 14, 2011, at 12:40 PM, Randall Nortman wrote: I'm having trouble getting mixins to play nicely with __table_args__. Using the example I gave earlier in this thread: On Jan 13, 1:00 pm, Michael Bayer mike

Re: [sqlalchemy] Re: Best way to reduce boilerplate?

2011-01-14 Thread Randall Nortman
On Fri, Jan 14, 2011 at 01:07:06PM -0500, Michael Bayer wrote: It's currently an unsolved problem how conflicting tuples/dicts would be reconciled automatically by declarative, and doing so would also make it impossible for implementations to override its behavior, since declarative would

[sqlalchemy] Best way to reduce boilerplate?

2011-01-13 Thread Randall Nortman
I am finding myself doing a fair amount of copy-and-paste in the data model I'm currently working on, and I'd like to reduce that if possible. For example, I have several different types of objects that have names belonging to namespaces. So every such table gets boilerplate looking like this

[sqlalchemy] Re: Best way to reduce boilerplate?

2011-01-13 Thread Randall Nortman
On Jan 13, 1:00 pm, Michael Bayer mike...@zzzcomputing.com wrote: [...] Mixins are extensively documented at http://www.sqlalchemy.org/docs/orm/extensions/declarative.html#mixin-classes So they are! I really should read the What's New in 0.x document before switching to 0.x. What a nice

[sqlalchemy] Re: Serializable txns not useful on sqlite because do_begin() does nothing

2010-09-20 Thread Randall Nortman
On Sep 20, 4:22 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Sep 20, 2010, at 3:51 PM, Randall Nortman wrote: On Sep 19, 1:52 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Sep 19, 2010, at 9:54 AM, Randall Nortman wrote: The DB-SIG list agrees with you: http

[sqlalchemy] Re: Serializable txns not useful on sqlite because do_begin() does nothing

2010-09-19 Thread Randall Nortman
On Sep 18, 11:59 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Sep 18, 2010, at 6:52 PM, Randall Nortman wrote: In testing my code for concurrency, I discovered that transactions are not properly isolated on sqlite, even with isolation_level='SERIALIZABLE'.  It turns out

[sqlalchemy] Serializable txns not useful on sqlite because do_begin() does nothing

2010-09-18 Thread Randall Nortman
In testing my code for concurrency, I discovered that transactions are not properly isolated on sqlite, even with isolation_level='SERIALIZABLE'. It turns out that on the sqlite dialect, do_begin() does nothing. As a result, transactions are not isolated as expected. Dirty writes are easy to

[sqlalchemy] Re: Serializable txns not useful on sqlite because do_begin() does nothing

2010-09-18 Thread Randall Nortman
On Sep 18, 6:52 pm, Randall Nortman wondercl...@gmail.com wrote: [...] isolated as expected.  Dirty writes are easy to construct; using the [...] Sorry, I meant lost update rather than dirty write. In my head I think of dirty read and dirty write, but I should translate to standard terminology

[sqlalchemy] Re: NULL values sorting

2009-09-28 Thread Randall Nortman
Coalesce will still work fine. Just use a string with an an appropriate sorting order in place of REALLY_BIG_VALUE. On Sep 28, 8:24 am, alex alexlp9...@gmail.com wrote: Sorry, I forgot. code0 is String values. and ordering like '001', '002', '043', '321', None

[sqlalchemy] Re: NULL values sorting

2009-09-25 Thread Randall Nortman
On Sep 25, 2:06 am, Alex alexlp9...@gmail.com wrote: Hello. I have a table like items id  code0   name [...] I use an order_by(code0) to sort query, and it sort like 1, 2, 43, 321, None. I need to get None-values to top, like None, 1, 2, 43, 321. Is it

[sqlalchemy] Pre-commit validation spanning multiple tables/ORM classes

2009-09-22 Thread Randall Nortman
In my application, I have a set of tables that model parts of what are conceptually composite objects, and I need to validate that the state of the objects is coherent before committing them to the database. In the course of building up the network of objects, the state may be temporarily