© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
1 reply
garyaustin

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();
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.
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Backup of snippets in SQL Editor
SupabaseSSupabase / help-and-questions
4y ago
Creating a random_username function with SQL Editor
SupabaseSSupabase / help-and-questions
4y ago
SQL Editor
SupabaseSSupabase / help-and-questions
7mo ago
RPC function to get sum of specific columns does not work in the SQL Editor
SupabaseSSupabase / help-and-questions
4y ago