Lists: | Postg토토 사이트SQL : |
---|
From: | Iaam Onkara <iamonkara(at)gmail(dot)com> |
---|---|
To: | pgsql-in-general(at)postgresql(dot)org |
Subject: | md5 checksum of a given/previous row |
Date: | 2017-11-12 18:26:33 |
Message-ID: | CAMz9UCYQHf8+U8KGwdvLvBvjgMcvt+i0nNpyO15jYP2gc-2ubg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | Postg토토 사이트SQL : |
Hi,
I have a requirement to create an tamper proof chain of records for audit
purposes. The pseudo code is as follows
before_insert:
1. compute checksum of previous row (or conditionally selected row)
2. insert the computed checksum in the current row
For now lets assume we are using md5 checksum, I can easily get the md5 of
current row using
select md5(textin(record_out(test))) as md5_checksum FROM test;
but how do I compute md5 of previous row or of a row selected by where
column=val;?
Thanks.
Onkara
From: | Iaam Onkara <iamonkara(at)gmail(dot)com> |
---|---|
To: | Niranjan <niranjan81(at)gmail(dot)com> |
Cc: | pgsql-in-general(at)postgresql(dot)org |
Subject: | Re: md5 checksum of a given/previous row |
Date: | 2017-11-12 19:55:22 |
Message-ID: | CAMz9UCaj1+c7_ktzoC5-1RM8ynSadqfPce+aLjkcfoeJnWyKCA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-in-general |
I have tried the *lag* function but that works one only one column which
means I can get md5 checksum for one column.
But how do I use *lag* or something like lag to get the whole of the
previous row?
Thanks
Onkara
On Nov 12, 2017 1:53 PM, iamonkara(at)gmail(dot)com wrote:
> I have tried the lag function but that works one only one column which
> means I can get md5 checksum for one column.
>
> But how do I use lag or something like lag to get the whole of the
> previous row.
>
> On Nov 12, 2017 1:22 PM, "Niranjan" <niranjan81(at)gmail(dot)com> wrote:
>
> What all combinations have you tried?
>
>
> On 12-Nov-2017 23:56, "Iaam Onkara" <iamonkara(at)gmail(dot)com> wrote:
>
> Hi,
>
> I have a requirement to create an tamper proof chain of records for audit
> purposes. The pseudo code is as follows
>
> before_insert:
> 1. compute checksum of previous row (or conditionally selected row)
> 2. insert the computed checksum in the current row
>
> For now lets assume we are using md5 checksum, I can easily get the md5 of
> current row using
>
> select md5(textin(record_out(test))) as md5_checksum FROM test;
>
> but how do I compute md5 of previous row or of a row selected by where
> column=val;?
>
> Thanks.
> Onkara
>
>
>
>
From: | Iaam Onkara <iamonkara(at)gmail(dot)com> |
---|---|
To: | Niranjan <niranjan81(at)gmail(dot)com> |
Cc: | pgsql-in-general(at)postgresql(dot)org |
Subject: | Re: md5 checksum of a given/previous row |
Date: | 2017-11-12 22:45:28 |
Message-ID: | CAMz9UCb8n9DCzf4P2ZMOziJzxrCqo3Hprdhgg+XKiRfpdwNmhw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-in-general |
Here are the different options that I have tried using lag and md5 functions
http://www.sqlfiddle.com/#!17/69843/2
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;
Still unable to figure out how to read the previous record as whole.
Thanks,
Onkara
On Sun, Nov 12, 2017 at 1:55 PM, Iaam Onkara <iamonkara(at)gmail(dot)com> wrote:
> I have tried the *lag* function but that works one only one column which
> means I can get md5 checksum for one column.
>
> But how do I use *lag* or something like lag to get the whole of the
> previous row?
>
> Thanks
> Onkara
>
> On Nov 12, 2017 1:53 PM, iamonkara(at)gmail(dot)com wrote:
>
>> I have tried the lag function but that works one only one column which
>> means I can get md5 checksum for one column.
>>
>> But how do I use lag or something like lag to get the whole of the
>> previous row.
>>
>> On Nov 12, 2017 1:22 PM, "Niranjan" <niranjan81(at)gmail(dot)com> wrote:
>>
>> What all combinations have you tried?
>>
>>
>> On 12-Nov-2017 23:56, "Iaam Onkara" <iamonkara(at)gmail(dot)com> wrote:
>>
>> Hi,
>>
>> I have a requirement to create an tamper proof chain of records for audit
>> purposes. The pseudo code is as follows
>>
>> before_insert:
>> 1. compute checksum of previous row (or conditionally selected row)
>> 2. insert the computed checksum in the current row
>>
>> For now lets assume we are using md5 checksum, I can easily get the md5
>> of current row using
>>
>> select md5(textin(record_out(test))) as md5_checksum FROM test;
>>
>> but how do I compute md5 of previous row or of a row selected by where
>> column=val;?
>>
>> Thanks.
>> Onkara
>>
>>
>>
>>
From: | Niranjan <niranjan81(at)gmail(dot)com> |
---|---|
To: | Iaam Onkara <iamonkara(at)gmail(dot)com> |
Cc: | pgsql-in-general(at)postgresql(dot)org |
Subject: | Re: md5 checksum of a given/previous row |
Date: | 2017-11-12 22:53:47 |
Message-ID: | CAMYjFn9dvhwk6tupAmO76-Y5vyK7DqOJ6=kXqu3JLVUibDJAqw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-in-general |
Thanks, I'll take a look.
On 13-Nov-2017 4:15 AM, "Iaam Onkara" <iamonkara(at)gmail(dot)com> wrote:
> Here are the different options that I have tried using lag and md5
> functions
>
> http://www.sqlfiddle.com/#!17/69843/2
>
> 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;
>
> Still unable to figure out how to read the previous record as whole.
>
> Thanks,
> Onkara
>
>
>
> On Sun, Nov 12, 2017 at 1:55 PM, Iaam Onkara <iamonkara(at)gmail(dot)com> wrote:
>
>> I have tried the *lag* function but that works one only one column which
>> means I can get md5 checksum for one column.
>>
>> But how do I use *lag* or something like lag to get the whole of the
>> previous row?
>>
>> Thanks
>> Onkara
>>
>> On Nov 12, 2017 1:53 PM, iamonkara(at)gmail(dot)com wrote:
>>
>>> I have tried the lag function but that works one only one column which
>>> means I can get md5 checksum for one column.
>>>
>>> But how do I use lag or something like lag to get the whole of the
>>> previous row.
>>>
>>> On Nov 12, 2017 1:22 PM, "Niranjan" <niranjan81(at)gmail(dot)com> wrote:
>>>
>>> What all combinations have you tried?
>>>
>>>
>>> On 12-Nov-2017 23:56, "Iaam Onkara" <iamonkara(at)gmail(dot)com> wrote:
>>>
>>> Hi,
>>>
>>> I have a requirement to create an tamper proof chain of records for
>>> audit purposes. The pseudo code is as follows
>>>
>>> before_insert:
>>> 1. compute checksum of previous row (or conditionally selected row)
>>> 2. insert the computed checksum in the current row
>>>
>>> For now lets assume we are using md5 checksum, I can easily get the md5
>>> of current row using
>>>
>>> select md5(textin(record_out(test))) as md5_checksum FROM test;
>>>
>>> but how do I compute md5 of previous row or of a row selected by where
>>> column=val;?
>>>
>>> Thanks.
>>> Onkara
>>>
>>>
>>>
>>>
>