Making views updatable
PostgreSQL supports the SQL standard CREATE VIEW
command, which supports automatic UPDATE
, INSERT
, and DELETE
commands, provided they are simple enough.
Note that certain types of updates are forbidden just because they are either impossible or impractical to derive a corresponding list of modifications on the constituent tables. We'll discuss those issues here.
Getting ready
First, you need to consider that only simple views can be made to receive insertions, updates, and deletions easily. The SQL standard differentiates between views that are simple and updatable, and more complex views that cannot be expected to be updatable.
So, before we proceed, we need to understand what a simple updatable view is and what it is not. Let's start with the cust
table:
postgres=# SELECT * FROM cust; customerid | firstname | lastname | age ------------+-----------+----------+----- ...