Get results of created function in SQL editor with select.

I think I know the answer, but just checking.
Basically I want to run explain analyze but also do several sql commands before that. This does not work because the SQL editor (and 3rd party Datagrip editor) don't return results if there are more than one sql command.

So an alternative would be to somehow create a function with the explain code in it and then display the result after running in the SQL editor.

CREATE OR REPLACE FUNCTION run_explain()
  RETURNS SETOF text AS
$$
BEGIN
   // more stuff here
   RETURN QUERY
   EXPLAIN ANALYZE SELECT * FROM messages;
END
$$ LANGUAGE plpgsql;
select * from run_explain();

This does not work for same reason above. Supabase SQL editor just returns successful and Datagrip asks which command to run.
Is there anyway to create/replace a function and get the result in the SQL editor I'm missing?
Otherwise doing two separate windows with the create and select I assume is as good as it gets.
Was this page helpful?