If I have a view on a view on a view (etc.), is there a way to show the full query that this expands/flattens to?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
migrated from stackoverflow.com May 12 '13 at 0:04
This question came from our site for professional and enthusiast programmers.
Not in PostgreSQL at this time. PostgreSQL doesn't actually build a single giant SQL statement; instead, it uses the plan tree of the view(s) and inserts that into the top level query's plan tree. To turn that back into SQL would require a deparser, something PostgreSQL doesn't have a the moment.
You can kind-of do-it-yourself by replacing references to the view with the text of the view query, but you need to understand that the effect isn't exactly the same, particularly where there are multiple references to the view.
You're best off using