CREATE TABLE test ("id" uuid DEFAULT uuid_generate_v4() NOT NULL, "value" decimal(5,2) NOT NULL, "delta" decimal(5,2), "created_at" timestamp default current_timestamp, "words" text, CONSTRAINT pid PRIMARY KEY (id) ) ;
INSERT INTO test (value, words) VALUES (51.0, 'A'), (52.0, 'B'), (54.0, 'C'), (57.0, 'D') ;
select created_at, value, value - lag(value, 1, 0.0) over(order by created_at) as delta, md5(lag(words,1,words) over(order by created_at)) as the_word, md5(textin(record_out(test))) as Hash FROM test ORDER BY created_at;
But how do I use lag function or something like lag to read the previous record as whole.
Thanks,
Onkara
PS: This was earlier posted in 'pgsql-in-general' mailing list, but I think this is a more appropriate list, if I am wrong I am sorry