agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Achilleas Mantzios <achill@matrix.gatewaynet.com>
To: pgsql-sql@postgresql.org
Subject: Re: md5 checksum of a previous row
Date: Mon, 13 Nov 2017 10:01:27 +0200
Message-ID: <2849b22d-ffff-9925-ebbc-7eeb1d778af5@matrix.gatewaynet.com> (raw)
In-Reply-To: <oubipl$q9i$1@blaine.gmane.org>
References: <CAMz9UCYU6Vx6E2mtFnvEoFptdmA48d-hHn3x0E-NWuy8Cby5kA@mail.gmail.com>
	<oubipl$q9i$1@blaine.gmane.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

+1 , cool!

On 13/11/2017 09:49, Thomas Kellerer wrote:
>> But how do I use lag function or something like lag to read the previous record as whole.
> You can reference the whole row by using the table name:
>
> select created_at,
>         value,
>         value - lag(value, 1, 0.0) over(order by created_at) as delta,
>         md5(lag(test::text) over(order by created_at)) as the_row
> FROM test
> ORDER BY created_at;
>
> The table reference "test" returns the whole row, e.g. something like:
>
>     (bbf35815-479b-4b1b-83c5-5e248aa0a17f,52.00,,"2017-11-13 08:45:16.17231",B)
>
> that can be cast to text and then you can apply the md5() function on the result.
> It does include the parentheses and the commas, but as it does that for every
> row in a consistent manner, it shouldn't matter.
>
>> 2. insert the computed checksum in the current row
> That can also be done using the above technique, something like:
>
>     new.hash := md5(new::text);
>
> Thomas
>
>
>
>
>
>

-- 
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt



-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



view thread (15+ messages)  latest in thread

Message-ID: <2849b22d-ffff-9925-ebbc-7eeb1d778af5@matrix.gatewaynet.com>
Permalink:  ../2849b22d-ffff-9925-ebbc-7eeb1d778af5@matrix.gatewaynet.com/
Also on:    postgresql.org/message-id/2849b22d-ffff-9925-ebbc-7eeb1d778af5@matrix.gatewaynet.com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: achill@matrix.gatewaynet.com
  Subject: Re: md5 checksum of a previous row
  In-Reply-To: <2849b22d-ffff-9925-ebbc-7eeb1d778af5@matrix.gatewaynet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox