Re: MD5 sums of large objects

From: "Dirk Jagdmann" <jagdmann(at)gmail(dot)com>
To: "Michael Fuhr" <mike(at)fuhr(dot)org>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: MD5 sums of large objects
Date: 2007-04-09 00:07:16
Message-ID: 5d0f60990704081707m56b29423ob5d63103623305b2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello Michael,

this works like charm. Although I did fix the argument for lo_lseek:

CREATE OR REPLACE FUNCTION md5(id oid)
RETURNS text
as $$
DECLARE
fd integer;
size integer;
hashval text;
INV_READ constant integer := 262144; -- 0x40000 from libpq-fs.h
SEEK_SET constant integer := 0;
SEEK_END constant integer := 2;
BEGIN
IF id is null THEN
RETURN NULL;
END IF;
fd := lo_open(id, INV_READ);
size := lo_lseek(fd, 0, SEEK_END);
PERFORM lo_lseek(fd, 0, SEEK_SET);
hashval := md5(loread(fd, size));
PERFORM lo_close(fd);
RETURN hashval;
END;
$$
language plpgsql stable strict;
comment on FUNCTION md5(id oid) is 'Calculates the md5 sum of a large object.';

I vote for this function beeing included either somewhere in the
contrib directories, as you often don't need the full power of
pgcrypto is md5 suffices for your hashing needs.

--
---> Dirk Jagdmann
----> http://cubic.org/~doj
-----> http://llg.cubic.org

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Fuhr 2007-04-09 01:07:27 Re: MD5 sums of large objects
Previous Message Tom Lane 2007-04-08 23:20:46 Re: Question on pgpsql function