Create primary key on materialized view in Postgres
Asked Answered
A

1

25

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 
Ahmadahmar answered 11/1, 2019 at 22:30 Comment(0)
C
40

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

create unique index on my_mat_view (id)
Conditional answered 11/1, 2019 at 22:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.