On Tuesday 13 January 2009 15:48:01 Chen Houwu wrote:
> I am not very familiar with SqlAlchemy, now I have a problem to query
> with aggregate function.
>
> Here is the class
> --------------------------
> class Directory(DeclarativeBase):
>     """An ultra-simple group definition.
>     """
>     __tablename__ = 'docman_directory'
>     dir_id = Column(Integer, autoincrement=True, primary_key=True)
>     code = Column(Integer,default=1)
>     parent_id = Column(Integer, ForeignKey
> ('docman_directory.dir_id'))
> --------------------------
> I want to get the result of " select max(code) from docman_directory
> where parent_id='222' ",  what  clause should I use with DBSession?
>
> I have tried:
> "DBSession.query(func.max('Document.doc_id')).filter_by

Try not passing it literal - why would you exepct that to work? Columns are 
objects in SA.

And if you had done that, you had seen that you wrote doc_id, where I guess 
you want dir_id?

I can't guarartee that it works, but I guess it should.

> (parent_id=self.dir_id).one()" but failed
> I have googled a lot, but still not clear how to deal with this
> situation.

Diez

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to