A view is similar to a table, both are relations - that is “something with columns”. All such objects are stored in the catalog table
pg_class. These are the general differences:
pg_class.relkindfor a view is
A view has an
ON SELECT query rewrite rule called
The rewrite rule contains the definition of the view and is stored in the
ev_action column of the
pg_rewrite catalog table.
For more technical information about views, see the PostgreSQL documentation about Views and the Rule System.
Also, a view definition is not stored as a string, but in the form of a query parse tree. Views are parsed when they are created, which has several consequences:
CREATE VIEW, so the current setting of
search_pathaffects the view definition.
Note that the way Greenplum Database handles views is quite different from the way Greenplum Database handles functions: function bodies are stored as strings and are not parsed when they are created. Consequently, Greenplum Database does not know on which objects a given function depends.
These system catalog tables contain the information used to determine the tables on which a view depends.
pg_class- object information including tables and views. The
relkindcolumn describes the type of object.
pg_depend- object dependency information for database-specific (non-shared) objects.
pg_rewrite- rewrite rules for tables and views.
pg_attribute- information about table columns.
pg_namespace- information about schemas (namespaces).
It is important to note that there is no direct dependency of a view on the objects it uses: the dependent object is actually the view’s rewrite rule. That adds another layer of indirection to view dependency information.