[sqlalchemy] Re: Cannot use add_entity to add result from subquery?

2009-07-15 Thread The Devil's Programmer
ok so the problem was that I was just calling query.add_column() without grabbing the result, ie.. query = query *facepalm* rookie mistake On Jul 15, 10:41 am, The Devil's Programmer thedevilsprogram...@gmail.com wrote: here is my code http://pastebin.com/m13075cc9 if that helps On

[sqlalchemy] Specifying Alternate Join Conditions to relation()

2009-07-15 Thread GHZ
using 5.5 from sqlalchemy import create_engine, Table, Column, ForeignKeyConstraint, MetaData, and_, String, Integer, ForeignKey from sqlalchemy.orm import relation, sessionmaker, synonym, join from sqlalchemy.ext.declarative import declarative_base engine = create_engine('sqlite:///:memory:')

[sqlalchemy] Re: Column expressions and .count()

2009-07-15 Thread Kyle Schaffrick
On Mon, 13 Jul 2009 19:18:39 -0400 Michael Bayer mike...@zzzcomputing.com wrote: Brad Wells wrote: Is it possible to perform a query.count() on a query with a labeled column expression without count() adding the subselect? I need to filter on the value of the expression and get a count

[sqlalchemy] How to filter by the result of a subquery?

2009-07-15 Thread The Devil's Programmer
I am currently performing a query with a joined subquery that gets the sum of votes on an article. The problem is that when I try to filter based on the result of that subquery, i get errors. Code outlining problem (very simple) - http://pastebin.com/m48905db6 Please tell me I don't have to

[sqlalchemy] Re: Column expressions and .count()

2009-07-15 Thread Michael Bayer
Kyle Schaffrick wrote: On Mon, 13 Jul 2009 19:18:39 -0400 Michael Bayer mike...@zzzcomputing.com wrote: Brad Wells wrote: Is it possible to perform a query.count() on a query with a labeled column expression without count() adding the subselect? I need to filter on the value of the

[sqlalchemy] Re: How to filter by the result of a subquery?

2009-07-15 Thread Michael Bayer
what is the SQL you would like emitted ? that is always the place to start. The Devil's Programmer wrote: I am currently performing a query with a joined subquery that gets the sum of votes on an article. The problem is that when I try to filter based on the result of that subquery, i get

[sqlalchemy] Re: Specifying Alternate Join Conditions to relation()

2009-07-15 Thread Michael Bayer
GHZ wrote: boston_addresses = relation('Address', primaryjoin = and_ ('User.user_id==Address.user_id', 'Address.city==Boston'), foreign_keys = ['Address.user_id']) the expression sent to primaryjoin must be an expression

[sqlalchemy] Re: Specifying Alternate Join Conditions to relation()

2009-07-15 Thread Mike Conley
I was getting ready to do something similar, and now I am confused. How is what GHZ is doing fundamentally different from the documentation example Specifying Alternate Join Conditions to relation()? Doesn't that example wrap the primaryjoin in the and_() construct also?

[sqlalchemy] Re: Specifying Alternate Join Conditions to relation()

2009-07-15 Thread Michael Bayer
Mike Conley wrote: I was getting ready to do something similar, and now I am confused. How is what GHZ is doing fundamentally different from the documentation example Specifying Alternate Join Conditions to relation()? Doesn't that example wrap the primaryjoin in the and_() construct also?

[sqlalchemy] Re: Specifying Alternate Join Conditions to relation()

2009-07-15 Thread Mike Conley
Ahh!! Starting to understand it. In this case, the entire expression to primaryjoin must be a string. The explanation about eval'ing the string when mappers are compiled makes sense. Now I see the relation in GHZ's example and in the code I will be writing should look something like this.

[sqlalchemy] Mapping MySQL geometry type.

2009-07-15 Thread J. Cliff Dyer
I'm trying to create a custom geometry type for MySQL, but I'm running up against my limited knowledge of SQLAlchemy. My goal is to be able to pass in a geos.Point object on INSERT and UPDATE, convert it to WKT representation ('POINT (1. 2.)'), and pass that to

[sqlalchemy] Re: Mapping MySQL geometry type.

2009-07-15 Thread Michael Bayer
J. Cliff Dyer wrote: I'm trying to create a custom geometry type for MySQL, but I'm running up against my limited knowledge of SQLAlchemy. My goal is to be able to pass in a geos.Point object on INSERT and UPDATE, convert it to WKT representation ('POINT (1.

[sqlalchemy] Re: Column expressions and .count()

2009-07-15 Thread Kyle Schaffrick
On Wed, 15 Jul 2009 10:35:24 -0400 Michael Bayer mike...@zzzcomputing.com wrote: Kyle Schaffrick wrote: On Mon, 13 Jul 2009 19:18:39 -0400 Michael Bayer mike...@zzzcomputing.com wrote: Brad Wells wrote: Is it possible to perform a query.count() on a query with a labeled

[sqlalchemy] Re: How to filter by the result of a subquery?

2009-07-15 Thread The Devil's Programmer
Ok so I understand now that this is a limitation in SQL, and that I cannot use the result of a subquery in the from clause within my where cause. I believe I am supposed to wrap the whole query inside another query and put the where clause on the outer query, would this be correct? I have tried

[sqlalchemy] Re: Column expressions and .count()

2009-07-15 Thread Michael Bayer
On Jul 15, 2009, at 5:03 PM, Kyle Schaffrick wrote: len(query) forces us to play games with the __iter__ method on query such that it can't be a real iterator. Hmm, I thought there was a __len__ magic method, such that len(something) is the same as something.__len__(), when the latter is