Collapse SQL Functions

The following collapse functions take two input sequences, left and right, and produce the result sequence of type double where the computed scalar result is the first element.

The two input sequences must be of the same type. If the two input sequences are of different lengths the operation will be performed on only the number of elements in the shorter of the two sequences.

Please use the links in the following table for more detailed explanations of the functions:

seq_wsum( left, right ) The first element of the result sequence is the weighted sum of the two sequences: left and right
seq_wavg( left, right ) The first element of the result sequence is the weighted average of the two sequences: left and right
seq_cov( left, right ) The first element of the result sequence is the covariance of the two sequences: left and right
seq_corr( left, right ) The first element of the result sequence is the correlation of the two sequences: left and right

Example

Following is an example code snippet demonstrating the collapse functions:

         
    -- seq_wsum, seq_wavg
            
     
    INSERT INTO SimpleSequence(testNumber,dVal1,dVal2)
    VALUES(5,'{2,3,4}','{1,2,4}');
     
    SELECT dVal1,dVal2,seq_wsum(dVal1,dVal2) AS "wsum" FROM SimpleSequence WHERE testNumber=5;
    SELECT dVal1,dVal2,seq_wavg(dVal1,dVal2) AS "wavg" FROM SimpleSequence WHERE testNumber=5;
     
    dVal1{}
    dVal2{}
    wsum
    -------------------------------------------------------------------------
    {2.000000, 3.000000, 4.000000}
    {1.000000, 2.000000, 4.000000}
    24.000000
     
    dVal1{}
    dVal2{}
    wavg
    -------------------------------------------------------------------------
    {2.000000, 3.000000, 4.000000}
    {1.000000, 2.000000, 4.000000}
    2.666667
     
    -- seq_cov, seq_corr
            
     
    INSERT INTO SimpleSequence(testNumber,dVal1,dVal2)
        VALUES(6,'{2,3,5,7}','{3,3,5,9}');
     
    SELECT dVal1,dVal2,seq_cov(dVal1,dVal2) AS "cov" FROM SimpleSequence WHERE testNumber=6;
    SELECT dVal1,dVal2,seq_corr(dVal1,dVal2) AS "corr" FROM SimpleSequence WHERE testNumber=6;
     
    dVal1{}
    dVal2{}
    cov
    ------------------------------------------------------------------------------
    {2.000000, 3.000000, 5.000000, 7.000000}
    {3.000000, 3.000000, 5.000000, 9.000000}
    4.500000
     
    dVal1{}
    dVal2{}
    corr
    ------------------------------------------------------------------------------
    {2.000000, 3.000000, 5.000000, 7.000000}
    {3.000000, 3.000000, 5.000000, 9.000000}
    0.956689