A very odd situation, where a query returns 1380 items, but when wrapped in a function, then same function returns a single row
I've tried deleting and recreating the function.
When called like this, via a function, 1 row is returned.
CREATE OR REPLACE FUNCTION get_temps(tid uuid) RETURNS uuid
LANGUAGE sql
AS
$$
WITH RECURSIVE
start_set (temp_id, display_name, parent_temp_id) AS
(SELECT t.temp_id, t.display_name, t.parent_temp_id
FROM temps t
WHERE t.temp_id = tid),
subitems (temp_id, display_name, parent_temp_id) AS
(SELECT s.temp_id, s.display_name, s.parent_temp_id
FROM start_set s
UNION ALL
SELECT t.temp_id, t.display_name, t.parent_temp_id
FROM temps t
JOIN subitems subs ON t.parent_temp_id = subs.temp_id)
SELECT temp_id
FROM subitems;
$$;
When called not-in-a-function-wrapper, it returns 1380 rows
WITH RECURSIVE
start_set (temp_id, display_name, parent_temp_id) AS
(SELECT t.temp_id, t.display_name, t.parent_temp_id
FROM temps t
WHERE t.temp_id = tid),
subitems (temp_id, display_name, parent_temp_id) AS
(SELECT s.temp_id, s.display_name, s.parent_temp_id
FROM start_set s
UNION ALL
SELECT t.temp_id, t.display_name, t.parent_temp_id
FROM temps t
JOIN subitems subs ON t.parent_temp_id = subs.temp_id)
SELECT temp_id
FROM subitems;
What am I not thinking of?
sub_tempsfor clarity. The intent is to find all temps starting with a given parenttid. I could not find a way to refactor this without thetemps.temp_id = tidgoing somewhere that limited all results. – New Alexandria May 20 '23 at 23:26start_setorstart_tempis unnecesary. Sure / thanks – New Alexandria May 20 '23 at 23:34