PostgreSQL - How to see the creation statement of a view?
How to see the creation of view in PostgreSQL?
1. Using psql
In psql, run this command:
\d+ my_view_name
2. Using SQL Query
SELECT pg_get_viewdef('my_view_name', TRUE);
An alternative query:
SELECT definition FROM pg_views WHERE viewname = 'my_view_name';
3. Using TablePlus GUI
In TablePlus, you can see the creation statement of a view by:
- Select view from the list in the left sidebar to open it
- Switch to the
structure
tab at the bottom of the window, or use shortcut keys Cmd + Ctrl + ]
Then you’ll see the creation statement for the current view.
Need a good GUI tool for PostgreSQL? Check out TablePlus. It’s native, beautiful, and available for free.