What is the exact difference between scalar SQL functions and aggregate SQL functions in SQLite?
I am getting a problem with the following code when attempting to create a new function in SQLite:
int sqlite3_create_function(
sqlite3 *db,
const char *zFunctionName,
int nArg,
int eTextRep,
void *pApp,
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
void (*xFinal)(sqlite3_context*)
);
For a scalar SQL function, xStep and xFinal must be null, and for an aggregate SQL function, xFunc must be null. I need to know which one to use and what the difference is.
A scalar function is a function that operates on scalar values — that is, it takes one (or more) input values as arguments directly and returns a value.
An aggregate function is a function that operates on aggregate data — that is, it takes a complete set of data as input and returns a value that is computed from all the values in the set.
By the way, these are the standard definitions of “scalar” and “aggregate” that you can find in any dictionary, and all these links are in the top five Google search results if you search for “scalar function” and “aggregate function”. That’s OK, we want StackOverflow to become the “definitive” answer for questions like this, but in the interest of “teaching a man to fish” I feel compelled to remind you that you should do your own homework before asking other people to help answer your questions.