The gripe is that the function puts the results of the CTE/select into a temp table for the follow-on query. That mean I have a name collision and have to drop the temp table.
[...]
What am I missing here in building the fence and losing the neighbours?
Best guess:
CREATE TEMP TABLE ... ON COMMIT DROP AS
or
DROP TABLE IF EXISTS ..
You show a lot of detail in the function but its not useful. Given the stated problem your queries or "SELECT '1'::text" both will exhibit the same behavior. What you don't show or describe, however, is how and when the function is called.