Postresql DB 9. *. I want to get from:
from
time | value | -----+---------+ 1 | A | 2 | A | 3 | A | 4 | B | 5 | B | this
time | value | length | buf_1 | buf_2 | -----+---------+--------+---------+-------+ 1 | A | 1 | A | A | 2 | A | 1 | A,A | A | 3 | A | 1 | A,A,A | A | 4 | B | 2 |A,A,A,B | A,B | 5 | B | 2 |A,A,A,B,B| A,B | where the column length, it seems to me, is approximately like this:
array_length(array_agg(distinct(values)), 1) but this will give me a finite length for all values, and I want the length to be recorded dynamically for time-ordered values, or at least get the time when value changes from A to B, i.e. time = 4 here thanks!