Inserting into a simple Postgres view

Postgres documentation says

Simple views are automatically updated: the system allows INSERT, UPDATE, and DELETE statements to be used in a view just as in a regular table.

He then lists a number of requirements. I believe my view meets all of these requirements, but if I try to insert into this view, I get an error:

psql:C355A12.txt:1702: ERROR:  cannot insert into a view
HINT:  You need an unconditional ON INSERT DO INSTEAD rule.

      

The view I am inserting is defined as:

CREATE VIEW locationsView
    AS SELECT lc_name, lc_min, lc_max, lc_sizeX, lc_sizeY
    FROM locations;

      

This is the table definition:

CREATE TABLE locations(
    lc_name LocationName NOT NULL,
    lc_min LocationMin NOT NULL
        DEFAULT 0,
    lc_max LocationMax NOT NULL
        DEFAULT 0,
    lc_sizeX LocationSizeX NOT NULL,
    lc_sizeY LocationSizeY NOT NULL,
    PRIMARY KEY (lc_name)
);

      

Domains used:

CREATE DOMAIN LocationName AS TEXT;
CREATE DOMAIN LocationMin AS INT;
CREATE DOMAIN LocationMax AS INT;
CREATE DOMAIN LocationSizeX As INT;
CREATE DOMAIN LocationSizeY As INT;

      

How can I get this "automatically updated" information described in the documentation?

I am using Postgres version 9.3.4.

+3


source to share


1 answer


You are reading the documentation for a newer version of PostgreSQL server than what you are connecting to startup (8.4).



PostgreSQL 9.3 introduces simply updatable view support. Your client psql

is version 9.3, but this does not affect server functionality when connecting to an 8.4 server.

+2


source







All Articles