Submitted on: 04-24-2001
Description:
Demonstrates how to return the number of records affected by an update in a plpgsql function. (Function actually searches a table looking for opportunities to guess someone's gender. It actually relies on gender_guess, not included, which looks up into a table of American first names and their usual gender.)
Code:
-- author: joel burton (jburton@scw.org)
-- public domain
CREATE FUNCTION "gender_assign" () RETURNS int AS '
declare
rec_affected int;
begin
update tblPers set gendercode=gender_guess(fname,mname) where gendercode=''?'';
GET DIAGNOSTICS rec_affected = ROW_COUNT;
return rec_affected;
end;
' LANGUAGE 'plpgsql';
|