pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dirk Jagdmann <jagdmann@gmail.com>
To: Michael Fuhr <mike@fuhr.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: MD5 sums of large objects
Date: Mon, 9 Apr 2007 02:07:16 +0200
Message-ID: <5d0f60990704081707m56b29423ob5d63103623305b2@mail.gmail.com> (raw)
In-Reply-To: <20070408173757.GA78999@winnie.fuhr.org>
References: <5d0f60990704081003p615530acx86257a70bff33fa4@mail.gmail.com>
	<20070408173757.GA78999@winnie.fuhr.org>

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



view thread (5+ messages)  latest in thread

Message-ID: <5d0f60990704081707m56b29423ob5d63103623305b2@mail.gmail.com>
Permalink:  ../5d0f60990704081707m56b29423ob5d63103623305b2@mail.gmail.com/
Also on:    postgresql.org/message-id/5d0f60990704081707m56b29423ob5d63103623305b2@mail.gmail.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: jagdmann@gmail.com, mike@fuhr.org
  Subject: Re: MD5 sums of large objects
  In-Reply-To: <5d0f60990704081707m56b29423ob5d63103623305b2@mail.gmail.com>

* 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