On Wed, 2003-12-17 at 06:30, Jon Earle wrote:
Is there a way to, when I add a record to a table, have the md5 hash
computed and stored in the same table and then returned to the calling
program?
I recommend that you write a trigger to compute the md5 and shove that into a column. There are several integrity advantages of having postgresql do it in a trigger: 1) you can guarantee that it gets done, 2) you don't have to worry about a clients lying about the md5 or computing the md5 in different ways, 3) the md5 gets computed regardless of how the record is inserted, and 4) you can attach the trigger to updates as well.
As for returning the md5 to the caller/client, that's probably best done with a function whose job is to insert a record and return the md5. I have functions like
serial# <- ins_record(datum,datum,datum), which merely do an insert into table and return the serial number for that record.
-Reece
--
Reece Hart, Ph.D. rkh@gene.com, http://www.gene.com/
Genentech, Inc. 650/225-6133 (voice), -5389 (fax)
Bioinformatics and Protein Engineering
1 DNA Way, MS-93 http://www.in-machina.com/~reece/
South San Francisco, CA 94080-4990 reece@in-machina.com, GPG: 0x25EC91A0
|