Question: I am using Postgres, one of the latest versions. Here is my code: -------------------------------------------------------- CREATE or replace FUNCTION testing_lockstep(_id_arr int[], _counter_arr int[], d_date date) RETURNS

I am using Postgres, one of the latest versions. Here is my code: -------------------------------------------------------- CREATE or replace FUNCTION testing_lockstep(_id_arr int[], _counter_arr int[], d_date date) RETURNS TABLE (uc__id int) LANGUAGE plpgsql AS $func$ DECLARE _id int; _counter int; d_date date; BEGIN FOR _id, _counter IN SELECT * FROM unnest (_id_arr, _counter_arr) t -- !! LOOP RETURN QUERY with orig_dataset as ( select a.uc_id, cr.imei,cr.points_geom ,cr.created_at as time_created from campaign_routes cr left join assets a on a.imei = cr.imei where cr.created_at::date > d_date ) select uc_id from orig_dataset; END LOOP; END $func$;

--------------------------------------------------------------------------------------------------

My function call is as follows:

SELECT * FROM testing_lockstep('{454,454}'::int[] , '{2,3}'::int[], TO_DATE('2017-01-03','YYYY-MM-DD') ); 

The issue is I am getting a null result set, even though if I hardcode the same date in the function body, then I am getting correct results, i.e. if I write:

where cr.created_at::date > '2023-01-17'::date 

then I am getting correct results.

Please note, in the main function body, I have ommited parts for the sake of brevity.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!