Notice that some of the SQL functions are so-called "scalar functions"
abs) and others are so-called "aggregate
That is a distinction in SQL semantics that quince simply passes through
to application code. So:
const query<float> abs_xs = points.select(abs(points->x)); const query<boost::optional<float>> max_x = points.select(max(points->x)); const query<double> sum_x = points.select(sum(points->x));
If you execute the query
you get the absolute values of each
points. There are
as many results as there are records in the the table.
If you execute
you get the greatest of all the
one result only. If
is empty, then there is no greatest
but there is still one result, viz.
boost::none. (That's because SQL's
produces a single SQL
NULL, and quince's
passes it on.)
sum also produces a single SQL
when there is no input, but I made an editorial decision not to pass
that on. Quince's
sum() returns zero when there is nothing
to add up. So if
is empty, the query
produces a single
We have seen some examples of queries that are guaranteed to produce just one computed result. Later we shall see that there are special means of executing such queries, and of embedding them in other queries.
>> provides the operators
and the methods
get_value_or(), which you can use in the same way
as the corresponding features of
const query<float> max_x_or_zero = points.select(max(points->x).get_value_or(0.f));
a server-side expression, i.e. the DBMS evaluates it all. In this context,
is a wrapper for SQL's
This is the technique that
sum() uses internally.
>> is a subclass of
>, so if you want to write code that
deals polymorphically with both types, use