[sqlalchemy] Re: group_by, count, and name count field as ?

2008-04-11 Thread Lukasz Szybalski
Also what would be a syntax to make a same selection using session.query(th)? what would you like the ORM query to return ? Object instances ? currently, using group_by() and such with Query implies you're getting individual column tuples back using _values(), in which case its

[sqlalchemy] Re: group_by, count, and name count field as ?

2008-04-11 Thread Michael Bayer
On Apr 11, 2008, at 10:41 AM, Lukasz Szybalski wrote: So I tried instead of doing: s = sqlalchemy .select ([th .RECORD_NO ,sqlalchemy .func .count (th .RECORD_NO )],sqlalchemy .and_ (th .APPLIED_TEST ==1,th.CODING_DATE=='20080404')).group_by(th.RECORD_NO).execute() do this:

[sqlalchemy] Re: group_by, count, and name count field as ?

2008-04-11 Thread Rick Morrison
File sqlalchemy/databases/mssql.py, line 499, in do_execute cursor.execute(SET IDENTITY_INSERT %s OFF % self .identifier_preparer.format_table(context.compiled.statement.table)) SystemError: 'finally' pops bad exception This seems to be some weird error either with pyodbc or with

[sqlalchemy] Re: group_by, count, and name count field as ?

2008-04-11 Thread Lukasz Szybalski
I.e., *all* columns from th are being added to the columns clause of the select. According to the SQL standard, these names all need to be added to the GROUP BY as well - if MS-SQL is allowing only a partial GROUP BY list, thats just poor behavior on the part of MS-SQL (MySQL has this

[sqlalchemy] Re: group_by, count, and name count field as ?

2008-04-11 Thread Michael Bayer
On Apr 11, 2008, at 12:51 PM, Lukasz Szybalski wrote: Is there a way to get this ? SELECT RECORD_NO, count(RECORD_NO) FROM table GROUP BY RECORD_NO (primary key is RECORD_ID) The only way I know how to do it is via sqlalchemy.select but I would like the query type of the return where my

[sqlalchemy] Re: group_by, count, and name count field as ?

2008-04-11 Thread Lukasz Szybalski
ok, I don't think we are on a same page. So let me explain what I want and maybe unconfused myself on what is a proper way to get data out of database via sqlalchemy orm style. Query class should not be confused with the Select class, which defines database SELECT operations at the SQL

[sqlalchemy] Re: group_by, count, and name count field as ?

2008-04-11 Thread Michael Bayer
On Apr 11, 2008, at 2:51 PM, Lukasz Szybalski wrote: Above statements should result in query like: 'select a,count(a) from x where b=5,c=6 group by a' In order to get ORM object I need to use query. (That is what I get from reading the sentence I quoted) From the above, what ORM object

[sqlalchemy] Re: group_by, count, and name count field as ?

2008-04-11 Thread Lukasz Szybalski
Above statements should result in query like: 'select a,count(a) from x where b=5,c=6 group by a' In order to get ORM object I need to use query. (That is what I get from reading the sentence I quoted) From the above, what ORM object would you like ? the one which has a as

[sqlalchemy] Re: group_by, count, and name count field as ?

2008-04-11 Thread Michael Bayer
On Apr 11, 2008, at 4:40 PM, Lukasz Szybalski wrote: It makes sense now. I assumed that ORM object will only return 1 column I group by, and a count. When it returns the full row then my group_by makes no sense. Thanks Lucas ps. The links were really helpful ! greatglad that

[sqlalchemy] Re: group_by, count, and name count field as ?

2008-04-10 Thread Michael Bayer
On Apr 10, 2008, at 5:11 PM, Lukasz Szybalski wrote: Hello, I am trying to do a simple query which gets id, count(*) group by id, s = sqlalchemy .select ([th .RECORD_NO ,sqlalchemy .func .count (th .RECORD_NO )],sqlalchemy .and_ (th .APPLIED_TEST