I’m discovering PL/ pgSQL and the functions creation. In order to create a code more human readable I would like use custom nested functions or in other words I want call a function with the results of one other. My functions are:
CREATE SCHEMA IF NOT EXISTS routing_roaddata_func;
CREATE OR REPLACE FUNCTION "routing_roaddata_func".get_nav_strand_ids(link_id_v bigint ) RETURNS TABLE
(nav_strand_ids bigint) as $$
BEGIN
RETURN QUERY select nav_strand_id from rdf_wvd_211f0_1.rdf_nav_strand where link_id = link_id_v ;
END;
$$ LANGUAGE plpgsql;
--------------
CREATE OR REPLACE FUNCTION "routing_roaddata_func".get_condition_type(strand_ids_v bigint) RETURNS TABLE
(condition_id_ bigint )
AS $$
BEGIN
condition_id_ := (select condition_type from rdf_wvd_211f0_1.rdf_condition where nav_strand_id = strand_ids_v );
END;
$$ LANGUAGE plpgsql;
---------------
CREATE OR REPLACE FUNCTION "routing_roaddata_func".get_condition_type2(strand_ids_v bigint, out condition_id_ bigint)
AS $$
BEGIN
condition_id_ := (select condition_type from rdf_wvd_211f0_1.rdf_condition where nav_strand_id = strand_ids_v );
END;
$$ LANGUAGE plpgsql;
----------------
And I get some troubles when I want use its. I try :
select "routing_roaddata_func".get_nav_strand_ids(820636761); -- works
select "routing_roaddata_func".get_condition_type("routing_roaddata_func".get_nav_strand_ids(820636761)); -- the returns is empty
select "routing_roaddata_func".get_condition_type2("routing_roaddata_func".get_nav_strand_ids(820636761)); -- works
select * from "routing_roaddata_func".get_condition_type("routing_roaddata_func".get_nav_strand_ids(820636761)); **--ERROR: set-returning functions must appear at top level of FROM**
It's annoying because my final goal is to add a where clause like that to detect the presence of one modality in the returned values.
select * from "routing_roaddata_func".get_condition_type("routing_roaddata_func".get_nav_strand_ids(820636761)) where condition_type = 23;
Someone could explain me the problem of the "set-returning functions" ? How can I proceed ?