Create primary key on materialized view in Postgres

Viewed 9021

How can I create a primary key on a materialized view in Postgres?

ALTER MATERIALIZED VIEW my_mat_view ADD PRIMARY KEY (id)

returns error:

Error in query: ERROR: "my_mat_view" is not a table 
1 Answers

Materialized views cannot have primary keys. You can use a unique index instead.

create unique index on my_mat_view (id)
Related