From: Jason Kirtland Date: Thu, 11 Sep 2008 18:44:36 +0000 (+0000) Subject: Note to self: save buffers before committing. X-Git-Tag: rel_0_5rc1~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=42d7298a50250d36547891d0bdb2f4022087c38c;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Note to self: save buffers before committing. --- diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index cb1773e5ae..c9f29e6be6 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -1038,8 +1038,20 @@ class Query(object): "Multiple rows were found for one()") def scalar(self): - """Return """ + """Return the first element of the first result or None. + >>> session.query(Item).scalar() + + >>> session.query(Item.id).scalar() + 1 + >>> session.query(Item.id, Item.name).scalar() + 1 + >>> session.query(func.count(Parent.id)).scalar() + 20 + + This results in an execution of the underlying query. + + """ ret = list(self)[0] if not isinstance(ret, tuple): return ret