single scalar value. scalar() takes no arguments and is
roughly equivalent to first()[0], value()
takes a single column expression and is roughly equivalent to
values(expr).next()[0].
objects such as Query(table.c.col) will return the "key"
attribute of the Column.
+ - Added scalar() and value() methods to Query, each return a
+ single scalar value. scalar() takes no arguments and is
+ roughly equivalent to first()[0], value()
+ takes a single column expression and is roughly equivalent to
+ values(expr).next()[0].
+
- Improved the determination of the FROM clause when placing SQL
expressions in the query() list of entities. In particular
scalar subqueries should not "leak" their inner FROM objects
return iter(q)
_values = values
+ def value(self, column):
+ """Return a scalar result corresponding to the given column expression."""
+
+ return self.values(column).next()[0]
+
@_generative()
def add_column(self, column):
"""Add a SQL ColumnElement to the list of result columns to be returned."""
sess = create_session()
orders = sess.query(Order).filter(Order.id.in_([2, 3, 4]))
self.assertEquals(orders.values(func.sum(Order.user_id * Order.address_id)).next(), (79,))
+ self.assertEquals(orders.value(func.sum(Order.user_id * Order.address_id)), 79)
def test_apply(self):
sess = create_session()