Materialized views and unique indexes

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Materialized views and unique indexes
Date: 2013-03-08 01:39:36
Message-ID: CAB7nPqT1GhYNWA1Cbv5LAm+baD9mYi31WzZ_aQ6CXWS+G1v4jA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

While testing materialized views, I found the following behavior with
unique indexes:
postgres=# create table aa as select generate_series(1,3) as a;
SELECT 3
postgres=# create materialized view aam as select * from aa;
SELECT 3
postgres=# create unique index aam_ind on aam(a);
CREATE INDEX
postgres=# insert into aa values (4);
INSERT 0 1
postgres=# insert into aa values (1);
INSERT 0 1
postgres=# refresh materialized view aam;
ERROR: could not create unique index "aam_ind"
DETAIL: Key (a)=(1) is duplicated.
postgres=# select * from aam;
a
---
1
2
3
(3 rows)

As expected, the refresh failed, but the error message is not really
user-friendly.
Shouldn't we output instead something like that?
ERROR: could not refresh materialized view because of failure when
rebuilding index"
DETAIL: key is duplicated.

Thanks,
--
Michael

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2013-03-08 02:33:53 Re: Materialized views and unique indexes
Previous Message Andres Freund 2013-03-08 00:09:21 Re: REFRESH MATERIALIZED VIEW locklevel