databasepostgresqlviewdefinitionsql-view

Show the CREATE VIEW code for a view in PostgreSQL?


Is there an easy way to see the code used to create a view using the PostgreSQL command-line client?

Something like the SHOW CREATE VIEW from MySQL.


Solution

  • Kept having to return here to look up pg_get_viewdef (how to remember that!!), so searched for a more memorable command... and got it:

    \d+ viewname
    

    You can see similar sorts of commands by typing \? at the pgsql command line.

    Bonus tip: The emacs command sql-postgres makes pgsql a lot more pleasant (edit, copy, paste, command history).