Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions