Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 42F06B5DC1D for ; Sun, 11 Sep 2011 01:26:50 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 99767-10 for ; Sun, 11 Sep 2011 04:26:44 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id AB408B5DC22 for ; Sun, 11 Sep 2011 01:26:43 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p8B4QfLq028538; Sun, 11 Sep 2011 00:26:41 -0400 (EDT) To: Thom Brown cc: pgsql-bugs Subject: Re: Dropped index on table preventing rule creation In-reply-to: References: Comments: In-reply-to Thom Brown message dated "Sun, 11 Sep 2011 01:35:11 +0100" Date: Sun, 11 Sep 2011 00:26:41 -0400 Message-ID: <28537.1315715201@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201109/66 X-Sequence-Number: 31083 Thom Brown writes: > I don't use rules, but in a bit of experimentation on Git master, I > discovered the following behaviour: > CREATE TABLE test1 (id serial primary key, things text); > CREATE TABLE test2 (id serial primary key, things text); > ALTER TABLE test1 DROP CONSTRAINT test1_pkey; > ALTER TABLE test2 DROP CONSTRAINT test2_pkey; > CREATE RULE "_RETURN" AS ON SELECT TO test1 DO INSTEAD select * from test2; > This produces the error message: could not convert table "test1" to a > view because it has indexes IIRC, this is because the check is just checking relhasindex. You should be able to recover and create the rule if you VACUUM the table. We could no doubt add more code to make that more transparent, but I don't see the point. The entire exercise of converting a table to a view is only meant to support loading of pg_dump output from versions that are probably ten years obsolete at this point. We don't even document that you can do the above, do we? (IOW, rather than "fix" this I'd prefer to rip out the code altogether. But maybe we should wait a couple more years for that.) regards, tom lane