![]() ![]() I have thrown in a function, just to show that a view can depend on objects other than tables. In the following, I’ll use this schema to test my queries: It is important to notice that there is no direct dependency of a view on the objects it uses: the dependent object is actually the view’s rewrite rule. deptype describes the kind of dependency.refclassid, refobjid and refobjsubid are like the three columns above, but describe the object referenced by the dependency.objsubid stores the column number if the dependency is for a column.objid stores the ID of the dependent object.classid stores the object ID of the catalog table containing the dependent object.How are the dependencies stored?Īll dependencies (except those on “shared objects”) are stored in the catalog table pg_depend: Consequently, PostgreSQL cannot know on which objects a given function depends. Note that the way PostgreSQL handles views quite different from the way PostgreSQL handles functions: function bodies are stored as strings and not parsed when they are created. PostgreSQL knows exactly which objects are used in the view definition, so it can add dependencies on them.Consequently, it is no problem to rename an object or column used in a view definition. Objects are referred to by their internal immutable “object ID” rather than by their name.Object names are resolved during CREATE VIEW, so the current setting of search_path applies.Views are parsed when they are created, which has several consequences: Note that the view definition is not stored as a string, but in the form of a “query parse tree”. This “query rewrite rule” contains the definition of the view and is stored in the ev_action column of the pg_rewrite catalog table. it has an ON SELECT rule called “ _RETURN”.it has no data file (because it holds no data).How are views stored in PostgreSQL?Ī view in PostgreSQL is not that different from a table: it is a “relation”, that is “something with columns”.Īll such objects are stored in the catalog table pg_class.Īs the documentation states, a view is almost the same as a table, with a few exceptions: Never forget that a view is just a “crystallized” SQL statement and gets replaced by its definition when the query is executed. ![]() People who do that tend to be surprised when certain WHERE conditions work well, but others take impossibly long.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |