[sqlalchemy] Sharding and COUNT

2008-04-11 Thread Geoff
Hi! I'm struggling to understand why the shard_chooser gets called for this query: SELECT count(users.uid) AS count_1 FROM users WHERE users.external_id = %s I would have thought this query_chooser should be called instead? shard_chooser gets set a mapper, a clause but the instance is None.

[sqlalchemy] Re: Sharding and COUNT

2008-04-11 Thread Geoff
I've figured out why it doesn't work. The scalar method on Session doesn't deal with sharding. On Apr 11, 11:55 am, Geoff [EMAIL PROTECTED] wrote: Hi! I'm struggling to understand why the shard_chooser gets called for this query: SELECT count(users.uid) AS count_1 FROM users WHERE

[sqlalchemy] Using substring function

2008-04-11 Thread maxi
Hi, I need to use substring function into sql statement. For it, I define the next sql: _sql = select([func.substring(planilladet.c.msg_debug, 1, 40).label('msg_debug'), func.sum(planilladet.c.cant).label('cant'), func.sum(planilladet.c.cant * planilladet.c.importe).label('importe')], \

[sqlalchemy] Re: Using substring function

2008-04-11 Thread maxi
(ProgrammingError) (-104, 'isc_dsql_prepare: \n Dynamic SQL Error\n SQL error code = -104\n Token unknown - line 1, column 39\n ,') 'SELECT substring(planilladet.msg_debug, ?, ?) AS msg_debug, sum(planilladet.cant) AS cant, sum(planilladet.cant * planilladet.importe) AS importe \nFROM

[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: Mapper issue with r4485

2008-04-11 Thread Michael Bayer
On Apr 10, 2008, at 8:46 PM, Steve Zatz wrote: I am not sure when the change was introduced but the following mapper, which previously worked: mapper(Section, section_table, properties = {'items': relation(Item, backref='section'), 'keywords':relation(Keyword, primaryjoin

[sqlalchemy] Access to the attributes of a session object (newbie)

2008-04-11 Thread [EMAIL PROTECTED]
Hello All, I have a session object, for instance: my_object = session.query(Person).filter_by(name='MYSELF').first() I know I can access to its attributes to modify the database: my_object.name = 'YOURSELF' my_object.town = 'PARIS' Is there a way to access its attributes on another way ? The

[sqlalchemy] Re: Mapper issue with r4485

2008-04-11 Thread Michael Bayer
On Apr 10, 2008, at 8:46 PM, Steve Zatz wrote: I am not sure when the change was introduced but the following mapper, which previously worked: mapper(Section, section_table, properties = {'items': relation(Item, backref='section'), 'keywords':relation(Keyword, primaryjoin

[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: Access to the attributes of a session object (newbie)

2008-04-11 Thread Michael Bayer
On Apr 11, 2008, at 11:45 AM, [EMAIL PROTECTED] wrote: Hello All, I have a session object, for instance: my_object = session.query(Person).filter_by(name='MYSELF').first() I know I can access to its attributes to modify the database: my_object.name = 'YOURSELF' my_object.town = 'PARIS'

[sqlalchemy] Re: Access to the attributes of a session object (newbie)

2008-04-11 Thread [EMAIL PROTECTED]
Magic ! It works perfectly. Thanks a lot Michael for your help and all your work. Dominique --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to

[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] SQLAlchemy hangs with Pydev 1.3.14, works with 1.3.13

2008-04-11 Thread David Gardner
This is probably not a SQLAlchemy issue, but thought I should share with the group in case there were other Pydev+Eclipse users out there. I recently came across an issue that when debugging code using Pydev, the code would hang whenever I tried to step over a statement of SQLAlchemy code. I

[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: Mapper issue with r4485

2008-04-11 Thread Steve Zatz
my hat's off to you for coming up with that relation(), it works again in rev 4486. Ah the irony ... check out http://tinyurl.com/6kqv94 And thanks as always for your remarkable responsiveness and for sqlalchemy. It is indispensible. Steve

[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: Using substring function

2008-04-11 Thread Lele Gaifax
On Fri, 11 Apr 2008 07:00:42 -0700 (PDT) maxi [EMAIL PROTECTED] wrote: The problem is with substring function, in SQL (I'm using Firebird 2.x) substring funcition sintax is: SUBSTRING(planilladet.msg_debug 1 FROM 40) How can do it in sqlalchemy ? (I use sqlalchemy 0.3.11) It's been