From: Michael Fuhr <mike@fuhr.org>
To: Dirk Jagdmann <jagdmann@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: MD5 sums of large objects
Date: Sun, 8 Apr 2007 11:37:57 -0600
Message-ID: <20070408173757.GA78999@winnie.fuhr.org> (raw)
In-Reply-To: <5d0f60990704081003p615530acx86257a70bff33fa4@mail.gmail.com>
References: <5d0f60990704081003p615530acx86257a70bff33fa4@mail.gmail.com>
On Sun, Apr 08, 2007 at 07:03:17PM +0200, Dirk Jagdmann wrote:
> I have a database containing lots of large objects. Now I'd like to
> compare large objects in my database and I thought of having a
> function which creates a hashsum (MD5, SHA-1 or whatever) of my large
> object, so I can use that in queries:
>
> create function lo_md5(id oid) returns text...
Something like this might work:
create function lo_md5(id oid) returns text as $$
declare
fd integer;
size integer;
hashval text;
INV_READ constant integer := 262144;
SEEK_SET constant integer := 0;
SEEK_END constant integer := 2;
begin
fd := lo_open(id, INV_READ);
size := lo_lseek(0, 0, SEEK_END);
perform lo_lseek(0, 0, SEEK_SET);
hashval:= md5(loread(fd, size));
perform lo_close(fd);
return hashval;
end;
$$ language plpgsql stable strict;
For hash functions other than MD5 see contrib/pgcrypto.
--
Michael Fuhr
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: mike@fuhr.org, jagdmann@gmail.com
Subject: Re: MD5 sums of large objects
In-Reply-To: <20070408173757.GA78999@winnie.fuhr.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox