Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fNlrx-0007j9-TR for pgsql-general@arkaria.postgresql.org; Tue, 29 May 2018 21:09:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fNlrw-0006St-1T for pgsql-general@arkaria.postgresql.org; Tue, 29 May 2018 21:09:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fNlrv-0006Sj-Ps for pgsql-general@lists.postgresql.org; Tue, 29 May 2018 21:09:23 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fNlro-0003CK-Uq for pgsql-general@postgresql.org; Tue, 29 May 2018 21:09:23 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w4TL9Egt010588; Tue, 29 May 2018 17:09:14 -0400 From: Tom Lane To: =?UTF-8?Q?Torsten_F=C3=B6rtsch?= cc: pgsql-general Subject: Re: How to drop a value from an ENUM? In-reply-to: References: Comments: In-reply-to =?UTF-8?Q?Torsten_F=C3=B6rtsch?= message dated "Tue, 29 May 2018 05:08:16 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <834.1527628154.1@sss.pgh.pa.us> Date: Tue, 29 May 2018 17:09:14 -0400 Message-ID: <835.1527628154@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =?UTF-8?Q?Torsten_F=C3=B6rtsch?= writes: > I am absolutely sure a certain value of one of my ENUM types is not used in > the entire database. Now I am asked to drop that value. Unfortunately, > there is no ALTER TYPE DROP VALUE. Yup. > On my development box I tried > delete from pg_enum > where enumtypid='my_type_name'::regtype > and enumlabel='my_label' > It worked and I could not find any adverse effects. > Given the value is not used anywhere, is this a save command? No. If it were, we'd have an ALTER DROP VALUE command. The key problem that is hard to fix here is that, even if today you have no live rows containing that value, it may still be present in indexes. In a btree, for example, the value might've migrated up into upper index pages as a page boundary value. Once that's happened, it's likely to persist indefinitely, even if the live occurrences in the underlying table get deleted and vacuumed away. Now, even if that's happened, you might be okay, because of the optimizations that typically allow enum value comparisons to be done without consulting pg_enum. But if you're in the habit of altering enums, it's that much more likely that you would have done an ALTER TYPE that defeats those optimizations; so I wouldn't rely on this. Sooner or later you're going to get burnt by complaints about an invalid enum value (not sure of the exact wording) when you access certain parts of the index. You could maybe get around all of that by reindexing any indexes containing the altered enum type after you're certain that all entries of the unwanted enum value are dead and vacuumed away. But it's not terribly safe. regards, tom lane