Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 7D8CF9FB225 for ; Sun, 8 Apr 2007 14:38:13 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 51223-04 for ; Sun, 8 Apr 2007 14:38:10 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 005E79FB1C6 for ; Sun, 8 Apr 2007 14:38:09 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.8/8.13.8) with ESMTP id l38Hbw8s013329 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 8 Apr 2007 11:38:01 -0600 (MDT) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.8/8.13.8) with ESMTP id l38HbvcY079072; Sun, 8 Apr 2007 11:37:57 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.8/8.13.8/Submit) id l38HbvrM079071; Sun, 8 Apr 2007 11:37:57 -0600 (MDT) (envelope-from mfuhr) Date: Sun, 8 Apr 2007 11:37:57 -0600 From: Michael Fuhr To: Dirk Jagdmann Cc: pgsql-sql@postgresql.org Subject: Re: MD5 sums of large objects Message-ID: <20070408173757.GA78999@winnie.fuhr.org> References: <5d0f60990704081003p615530acx86257a70bff33fa4@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5d0f60990704081003p615530acx86257a70bff33fa4@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/93 X-Sequence-Number: 28093 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