Sometimes you want to process the EXPLAIN output in SQL. Unfortunately, EXPLAIN itself does not offer that option. However, there are tricks... Wrapping EXPLAIN in a function This is probably the simpler version. It requires to create a function: CREATE OR REPLACE FUNCTION explain( p_q TEXT, p_mod TEXT[