[sqlalchemy] Re: select distinct on a relation to an entity with composite primary key

2011-01-24 Thread NiL
thank you very much michael, this is some kind of mind spinning sqla expression !! -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to

[sqlalchemy] Re: select distinct on a relation to an entity with composite primary key

2011-01-20 Thread NiL
Hi Michael, thank you very much for your prompt answer. What I want to achieve is, counting the number of distinct items, grouped by user_name Given Item1: item_id = 1 service_id = 'test' item_class = 'dummy' Item2: item_id = 2 service_id = 'other' item_class = 'dummy'

Re: [sqlalchemy] Re: select distinct on a relation to an entity with composite primary key

2011-01-20 Thread Michael Bayer
from sqlalchemy import func, distinct query(Invoice.user_name, func.count(distinct(Item.id))).join(Invoice.items).group_by(Invoice.user_name) On Jan 20, 2011, at 9:51 AM, NiL wrote: Hi Michael, thank you very much for your prompt answer. What I want to achieve is, counting the number

[sqlalchemy] Re: select distinct on a relation to an entity with composite primary key

2011-01-20 Thread NiL
thanks again but the unicity of Item is guaranteed by the triplet of PK I can't just discriminate the distinct() based on the item_id only (it is not unique by itself in my set of data) -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to

Re: [sqlalchemy] Re: select distinct on a relation to an entity with composite primary key

2011-01-20 Thread Michael Bayer
session.query(Invoice.user_name, Item).join(Invoice.item).distinct().from_self(Invoice.user_name, func.count(1)).group_by(Invoice.user_name) On Jan 20, 2011, at 11:45 AM, NiL wrote: thanks again but the unicity of Item is guaranteed by the triplet of PK I can't just discriminate the