Can I use PostgreSQL function in join? also can I use cursor function in join? actually this is what I want
Select m.* from Medication m
Left Join public.GetResidentMedications(, , , , , ,) f on f.Id= m.Id
same with the cursor functions?
**Below is my function which is a cursor function and I want to join it **
CREATE OR REPLACE FUNCTION public."GetResidentMedications" (
ref refcursor,
_alfid integer,
_residentid integer,
_types varchar,
_limits integer,
_offsets integer
)
RETURNS refcursor AS
$body$
BEGIN
open ref for
-- select * from public."GetResidentMedications"('refcursor', 25, 331, '' , 20, 1)
with cte AS (
select m."Id"
from public."Medication" m
where m."AlfId" = _AlfId
and (m."ResidentId" = _ResidentId or coalesce (_ResidentId, 0) = 0)
and 1 = (
case when
'IsVerified' = ANY ('{IsVerifiedsss, IsVerifieds}') and m."IsVerified" = true then 1 else 0 end
)
)
select * from (
table cte order BY "Id" limit _limits offset _offsets
) sub
Left join (select count("Id") from cte) c(TotalRecords) on true;
return ref;
END;
$body$
LANGUAGE 'plpgsql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
PARALLEL UNSAFE
COST 100;
is it possible to do it?
'IsVerified' = ANY ('{IsVerifiedsss, IsVerifieds}')makes no sense - that will always evaluate tofalse