Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 8C6FB9FAE4E for ; Sun, 8 Apr 2007 21:07:21 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 69016-07 for ; Sun, 8 Apr 2007 21:07:18 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.181]) by postgresql.org (Postfix) with ESMTP id 918729FA468 for ; Sun, 8 Apr 2007 21:07:18 -0300 (ADT) Received: by py-out-1112.google.com with SMTP id a73so923574pye for ; Sun, 08 Apr 2007 17:07:17 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=PpISKoESMj/ftPa1ZojQln3DdqfCMnFCuVBasr50a+tZQoYt2wUpav0/RTJ6NkMM/sHzxoZ94pWGwcb/eY9/dMIm23YMKXRNe+0C7Mc2vj8qkG++lerph74SVeqCfvu08mEZr9OVArUAm91MVk4DYsT0PmbuJNmeHBJDJx+UndI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=AzcllJ6ehywYDptScPTJVpe0PK9yfR3q6+QI5oSfUHYIIl7HTHruQmPRhcKh8QKr+fD9SttTX/YTIKzu4iG2CtdhEkjPJw3d+LXPBgtXk1REk24AGUZoxhOl/9IiqvtBiP6ISeM2ie5zpGruiB+FDKcRBqAbhjV6t9FmayoDJAY= Received: by 10.65.204.7 with SMTP id g7mr10570532qbq.1176077236897; Sun, 08 Apr 2007 17:07:16 -0700 (PDT) Received: by 10.64.112.5 with HTTP; Sun, 8 Apr 2007 17:07:16 -0700 (PDT) Message-ID: <5d0f60990704081707m56b29423ob5d63103623305b2@mail.gmail.com> Date: Mon, 9 Apr 2007 02:07:16 +0200 From: "Dirk Jagdmann" To: "Michael Fuhr" Subject: Re: MD5 sums of large objects Cc: pgsql-sql@postgresql.org In-Reply-To: <20070408173757.GA78999@winnie.fuhr.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <5d0f60990704081003p615530acx86257a70bff33fa4@mail.gmail.com> <20070408173757.GA78999@winnie.fuhr.org> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/97 X-Sequence-Number: 28097 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