How to do it…

There is nothing to do for simple views—PostgreSQL will propagate modifications to the underlying table automatically.

Conversely, if the view is not simple enough, but you still have a clear idea of how you would like to propagate changes to the underlying table(s), then you can allow updatable views by telling PostgreSQL how to actually perform DML statements. (DML stands for Data Manipulation Language, which in PostgreSQL means INSERT, UPDATE, DELETE or TRUNCATE).

PostgreSQL supports two mechanisms to achieve updatable views, namely rewrite rules and INSTEAD OF triggers. The latter provide a mechanism to implement updatable views by creating trigger functions that execute arbitrary code every time a data-modification command ...

Get PostgreSQL 10 Administration Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.