我在 postgresql 的 pl/pgsql 中有函数
IE
CREATE or replace FUNCTION check_checklist_is_finalizedtest(application_id bigint)
RETURNS SETOF record AS
$BODY$
DECLARE
sqlresult record;
val boolean:=false;
BEGIN
for sqlresult in execute IMMEDIATE 'select distinct mda.application_id maid,mda.document_type_id mdoctypeid,
dt.multiple_doc dtmdoc,mda.mandatory_doc_application_id mdocaid,COALESCE(ac.doc_correct,false) doccorrect,
COALESCE((select max(e_certificate_no) from application_document ad
where ad.application_id=mda.application_id and ad.document_id=mda.document_type_id and multiple_doc=true and ad."valid"=''||New||''
),'''||1||''')as no_of_docs,
(select count(*) from application_document ad2
where ad2.application_id=mda.application_id and ad2.document_id=mda.document_type_id and ad2."valid"=''||New||''
)as count_of_record
from mandatory_doc_application mda
inner join document_type dt on(mda.document_type_id=dt.document_id)
left join application_checklist ac on(ac.man_doc_app_id= mda.mandatory_doc_application_id)
where mda.application_id='''||$1||''''
LOOP
IF(sqlresult.no_of_docs::bigint=sqlresult.count_of_record and sqlresult.doccorrect=true) then
val=true;
ELSE
val=false;
END IF;
return next sqlresult;
END LOOP;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
当函数被调用时,select语句中的子查询没有被执行。因此结果是错误的。你能帮帮我吗?