[sqlalchemy] Question about joins and how the data is returned by the Query class

2009-07-14 Thread The Devil's Programmer
In my controller I have: query = session.query(Article, Category, User, UserVote) query = query.outerjoin((UserVote, and_ (Article.id==UserVote.article_id, UserVote.voter==currently_logged_in_user))) query = query.outerjoin((Category, Article.category_id == Category.id)) query =

[sqlalchemy] Question about joins and how the data is returned by the Query class

2009-07-14 Thread The Devil's Programmer
In my controller I have: query = session.query(Article, Category, User, UserVote) query = query.outerjoin((UserVote, and_ (Article.id==UserVote.article_id, UserVote.voter==currently_logged_in_user))) query = query.outerjoin((Category, Article.category_id == Category.id)) query =

[sqlalchemy] Re: Question about joins and how the data is returned by the Query class

2009-07-14 Thread Michael Bayer
The Devil's Programmer wrote: So what I am trying to figure out, is if there is a way to have the query return None in place of the missing UserVote when the user is not logged in? I'm hoping there might be some kind of .join_placeholder(UserVote) method that I have somehow overlooked, or

[sqlalchemy] Re: How to get inserted ids after row insert?

2009-07-14 Thread Roy Hyunjin Han
Hi Michael, Does the behavior of result.lastrowid change after SQLAlchemy version 5.5? It seems that in older versions lastrowid is the first id inserted and in later versions lastrowid is the last id inserted. RHH On Fri, Apr 10, 2009 at 11:57 AM, Michael Bayermike...@zzzcomputing.com wrote:

[sqlalchemy] Manipulation of query results

2009-07-14 Thread Alex
I'm running a sqlalchemy query to get the average time per day a user has spent on our website. The query runs properly and returns a list of rowtuples that represent timedelta objects, so now I'm trying to compute the average timedelta in this list. However, since each timedelta object is of

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

2009-07-14 Thread The Devil's Programmer
I can do this - comment_count_subquery = meta.Session.query(Comment.article_id, func.count('*').label('article_comment_count')).group_by (Comment.article_id).subquery() query = meta.Session.query(Article, comment_count_subquery.c.article_comment_count) but when I do it like this - query =

[sqlalchemy] Re: How to get inserted ids after row insert?

2009-07-14 Thread Michael Bayer
lastrowid is not supported by DBAPI when executemany() is used, it only applies towards a single INSERT that has inserted a single row. it remains a straight passthrough from the DBAPI and there's no difference in behavior on the SQLA side. Roy Hyunjin Han wrote: Hi Michael, Does the

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

2009-07-14 Thread Michael Bayer
The Devil's Programmer wrote: I can do this - comment_count_subquery = meta.Session.query(Comment.article_id, func.count('*').label('article_comment_count')).group_by (Comment.article_id).subquery() query = meta.Session.query(Article, comment_count_subquery.c.article_comment_count) but

[sqlalchemy] Re: convert_unicode and Query strings with a helping of PyODBC and FreeTDS on OS X

2009-07-14 Thread Ed Singleton
On 8 Jul 2009, at 07:29, John Hampton wrote: John Hampton wrote: So, the problem that I am having is that when I try to do a query, I get back the following error: sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('The SQL contains 0 parameter markers, but 1 parameters were

[sqlalchemy] Re: Question about joins and how the data is returned by the Query class

2009-07-14 Thread The Devil's Programmer
Thanks, works like a charm :) On Jul 15, 2:27 am, Michael Bayer mike...@zzzcomputing.com wrote: The Devil's Programmer wrote: So what I am trying to figure out, is if there is a way to have the query return None in place of the missing UserVote when the user is not logged in? I'm

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

2009-07-14 Thread Michael Bayer
The Devil's Programmer wrote: using add_column does not seem to work the same as including both items in the query [like below] query = meta.Session.query(Article, comment_count_subquery.c.article_comment_count) it does not return an iterable result is there any way to add subqueries to

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

2009-07-14 Thread The Devil's Programmer
well instead of returning an iterable array of Articles, its just returning a single Article On Jul 15, 10:17 am, Michael Bayer mike...@zzzcomputing.com wrote: The Devil's Programmer wrote: using add_column does not seem to work the same as including both items in the query [like below]

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

2009-07-14 Thread The Devil's Programmer
here is my code http://pastebin.com/m13075cc9 if that helps On Jul 15, 10:22 am, The Devil's Programmer thedevilsprogram...@gmail.com wrote: well instead of returning an iterable array of Articles, its just returning a single Article On Jul 15, 10:17 am, Michael Bayer