In the below code, the FOR doc IN SELECT ... loop was returning a NULL in doc_typeid - impossible because it has a foreign key constraint on it. By luck I found that modifying it to FOR doc in SELECT doc_id, doc_typeid
magically forced the correct value into doc_typeid (luck because I didn't need to select doc_id). When I changed the declaration of doc to record instead of a rowtype and removed the kludgey doc_id from the SELECT, it also worked correctly. These different tests led me to conclude that something other than the list of selected columns in the SELECT was determining the result set - perhaps the columns as ordered in the doc table at the last creation or alter table event are driving the population of the rowtype variable instead. So perhaps because record does not depend on any tables, my workaround to replace the rowtype declaration with record worked first time.
CREATE OR REPLACE FUNCTION public."doct_GetActMask"(
parm_holtype character varying)
RETURNS integer AS
actmask integer := 0;
doctpid integer := NULL;
approved integer := NULL;
verified integer := NULL;
logok integer := NULL;
WHERE docs_shortname = 'Approved'
WHERE docs_shortname = 'Verified'
FOR doc IN SELECT doc_type_id
WHERE doc_hol_id = parm_holid
AND (doc_docsid = approved OR doc_docsid = verified)
SELECT public."doct_GetRoot"(doc.doc_type_id) INTO doctpid;
IF doctpid < 0 THEN
actmask := actmask | (1<<(doctpid-1));
LANGUAGE plpgsql VOLATILE
ALTER FUNCTION public."doct_GetActMask"(bigint, character varying)
OWNER TO mydbo;