On Mon, Sep 21, 2015 at 9:11 AM, Prakash Premkumar <prakash.prax at gmail.com> wrote: > I'm reading the sqlite parser grammar. > > I could not find the grammar rules which parses aggregate functions like > MAX,MIN,SUM,COUNT,TOTAL. > > Can you please tell me how the aggregate functions are parsed (the grammar > rule that parses them)
A call to an aggregate function is parsed the same way as a call to an ordinary function. Sqlite then looks up the function name and number of arguments to determine if this corresponds to an ordinary function or an aggregate function, and changes the meaning of the query according to that. The page http://sqlite.org/lang_select.html details how the meaning of a SELECT statement changes if the selected expression contains an aggregate function: it becomes an aggregate query even if there is no GROUP BY clause, and it computes one result row from all the input rows. Aggregate functions can also be used in the expression of ordinary aggregate queries, containing a GROUP BY clause, or in the HAVING clause of such a query. I probably forgot a few more uses of aggregate functions, but in most other contexts, an aggregate function found in an expression results in an error. Ambrus