> > So it appears that Query.count() returns a row count for that
> > particular query, which len(Query.all()) obviously returns an object
> > count.
>
> using query.distinct() along with whatever joins and then count()
> should be counting only distinct rows of the primary table in the
> query, since only those columns get placed into the columns clause of
> the select. as long as you aren't calling add_entity() or add_column().
>
> of course we love examples here if you'd like to show us what you're
> doing.
Hi, thanks Michael - using distinct() works a treat.
Here's a summary of what I'm doing: I have a table representing
webpages and a table representing tags, a webpage has many tags.
site_table = Table('site', metadata,
Column('id', Integer, primary_key=True),
Column('site', Unicode(1024), nullable=False)
)
keyword_table = Table('keyword', metadata,
Column('id', Integer, primary_key=True),
Column('keyword', Unicode(64), nullable=False),
Column('site_id', Integer, ForeignKey('site.id',
onupdate='CASCADE', ondelete='CASCADE'))
)
mapper(Site, site_table,
properties = dict(
_keywords=relation(Keyword, backref='site'),
keywords = synonym('_keywords')
)
)
mapper(Keyword, keyword_table)
My query WAS Site.query.join('keywords').count(), but following your
advice it's now Site.query.join('keywords').distinct().count().
James
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---