RefLib

Reference library for AI

Back

postgresql_16:6.4.2 Views and the Rule System

PostgreSQL 16 > Server Programming > The Rule System > Views and the Rule System

Views in PostgreSQL are implemented using the rule system. A view is basically an empty table (having no actual storage) with an ON SELECT DO INSTEAD rule. Conventionally, that rule is named _RETURN. So a view like CREATE VIEW myview AS SELECT * FROM mytab; is very nearly the same thing as CREATE TABLE myview (*same column list as mytab*); CREATE RULE "_RETURN" AS ON SELECT TO myview DO INSTEAD SELECT * FROM mytab; although you can't actually write that, because tables are not allowed to have ON SELECT rules.

A view can also have other kinds of DO INSTEAD rules, allowing INSERT, UPDATE, or DELETE commands to be performed on the view despite its lack of underlying storage. This is discussed further below, in (see postgresql_16:6.4.2.4).

Subsections

Back