我在PL/pgSQL函數在PostgreSQL中子查詢在PL/pgSQL裏沒有工作
即
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語句子查詢不executed.Hence結果是錯誤的。你可以幫我嗎?
不要卸載你的混亂到這個論壇。以可讀的方式呈現您的代碼,並至少添加基本解釋您正在做的事情。添加你的Postgres版本並描述出了什麼問題(哪個「子查詢」沒有執行?)。 –