I have created a function that returned a table with one row and three columns.
DROP FUNCTION IF EXISTS get_event_deposit_values(INTEGER, date, date);
CREATE OR REPLACE FUNCTION get_event_deposit_values(event_id INTEGER, start_date date, end_date date)
RETURNS TABLE (carried_over INTEGER, current_month INTEGER, deposit INTEGER)
AS $$
DECLARE status INTEGER;
BEGIN
carried_over := 0;
current_month := 0;
deposit := 0;
RETURN QUERY
SELECT carried_over, current_month, deposit;
END
$$ LANGUAGE plpgsql;
Run a simple query in pgAdmin.
select * FROM get_event_deposit_values(20170913, '1999/01/01', '2018/05/11');
It returns three columns with one row.
Then, run a query in conjunction with main query (saw it on a website).
select t.id from t_events AS t, lateral get_event_deposit_values(t.id, '1999/01/01', '2018/05/11') where id = 20170913;
An error occurred near get_event_deposit_values(t.id
. The PostgreSQL I am running is of version 8.3 which is pretty outdated. Is there any alternative way of doing this?