FoundationDB/sql-layer — pull request #1031 by MMcM (2013-11-06 23:06:43+00:00)
Title: Add some more functions

* ASCII. This is like the function of that name in Postgres or the UNICODE function in MSSQL. It returns the first Unicode codepoint in the given string. See test case for non-ASCII examples.
* REPLACE. Like in MySQL.
* VAR and STDDEV in _POP and _SAMP versions. I did not add plain STDDEV or VARIANCE. Although most older dialects have these, they disagree as to whether they are the population or the sample version. So it seems best to stick to the standard.

The transformation of these aggregates also needs a little explanation. We only have Aggregate_Partial, which is designed to be placed more than once in a plan sometimes (although we do not do that presently). It therefore only deals with things that are well behaved wrt partial aggregation. So, AVG has a SUM and a COUNT, because you can take these and SUM them multiple times and still get the right answer with a divide at the end. In much the same way, the new aggregates maintain a SUM, a SUM of squares and a COUNT. Again, you can SUM these three as many more times as you need. The final answer is then Σx² - (Σx)² / N divided by N or N-1 and maybe √, all depending on the particular function.