On Nov 13, 2007, at 5:17 PM, Andrew Stromnov wrote:

>
> I have this SQL expression (from 
> http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html)
>
> SELECT b.*
> FROM tagmap bt, bookmark b, tag t
> WHERE bt.tag_id = t.tag_id
> AND (t.name IN ('bookmark', 'webservice', 'semweb'))
> AND b.id = bt.bookmark_id
> GROUP BY b.id
> HAVING COUNT( b.id )=3
>
> How to implement this "HAVING COUNT(b.id) = 3" in ORM?
>

upgrade to trunk revision 3769.  use the having() method on Query in  
conjunction with group_by().

However, that query doesnt seem correct to me; it will fail in  
Postgres because the GROUP BY clause is invalid - it needs to name  
each column in the columns clause of the select (i.e. everything in  
b.*) that is *not* part of the aggregate criterion in having().

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to