Is it possible to union a to union a variable to a select statement in PostgreSQL? I have a recursive function at the moment that in essence does this:
create or replace function call_recurrsive_function(ids bigint[]) . . select id from x where y union call_recurrsive_function(select id from x where y) .
I've recently made some changes that increase the complexity of the select by a lot, and to increase performance I'd like to run that query only once per function call and do something like
var = select id from x where y union call_recurrsive_function(var)
You can try using a CTE (Common Table Expression). For example:
with r as ( select id from x where y ) select * from ( select id from r union call_recurrsive_function(select id from r) ) x
2.1m questions
2.1m answers
60 comments
57.0k users