Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 4485AB5DBDB for ; Wed, 28 Sep 2011 11:51:52 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 58667-02 for ; Wed, 28 Sep 2011 14:51:45 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from lists.commandprompt.com (host-215.commandprompt.net [207.173.203.215]) by mail.postgresql.org (Postfix) with ESMTP id ACAACB5DBCD for ; Wed, 28 Sep 2011 11:51:45 -0300 (ADT) Received: from perhan.alvh.no-ip.org (spinlock.commandprompt.com.commandprompt.com [207.173.203.215]) by lists.commandprompt.com (Postfix) with ESMTPA id B472A34C39D; Wed, 28 Sep 2011 07:51:43 -0700 (PDT) Received: from perhan.alvh.no-ip.org ([200.126.68.131] helo=perhan.alvh.no-ip.org) by assp.commandprompt.com with ESMTP (2.0.1); 28 Sep 2011 07:51:41 -0700 Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 8D4BB6E36E; Wed, 28 Sep 2011 11:51:40 -0300 (CLST) Content-Type: text/plain; charset=UTF-8 Cc: mmoncure , Pg Bugs Subject: Re: Problems with ENUM type manipulation in 9.1 From: Alvaro Herrera To: depstein In-reply-to: <29F36C7C98AB09499B1A209D48EAA615B7653DBCAB@mail2a.alliedtesting.com> References: <29F36C7C98AB09499B1A209D48EAA615B7653DBC8A@mail2a.alliedtesting.com> <29F36C7C98AB09499B1A209D48EAA615B7653DBCAB@mail2a.alliedtesting.com> Date: Wed, 28 Sep 2011 11:51:40 -0300 Message-Id: <1317220852-sup-4032@alvh.no-ip.org> User-Agent: Sup/git Content-Transfer-Encoding: 8bit X-Assp-Version: 2.0.1(3.2.15) on assp.commandprompt.com X-Assp-Client-TLS: yes X-Assp-ID: assp.commandprompt.com m1-21503-13780 X-Assp-Original-Subject: Re: [BUGS] Problems with ENUM type manipulation in 9.1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201109/213 X-Sequence-Number: 31230 Excerpts from depstein's message of mié sep 28 07:21:17 -0300 2011: > > -----Original Message----- > > From: Merlin Moncure [mailto:mmoncure@gmail.com] > > Sent: Tuesday, September 27, 2011 10:31 PM > > > 1. We can use ALTER TYPE to add enum values, but there is no matching > > command to remove values, which makes this an incomplete solution. > > > > you can manually delete from pg_enum. this is dangerous; if you delete an > > enum value that is in use anywhere, behavior is undefined. > > True: Postgres doesn't do any checks when deleting enum values, which contrasts with the general practice of disallowing the removal of objects that are still referenced elsewhere in the database. That seems like a bug to me. We don't support deleting of enum values, precisely because there's no easy way to determine if they are in use somewhere. So there's no reason to think that we should do any checks when "deleting enum values". Keep in mind that manually fiddling with the system catalogs is not supported; if you break stuff by doing it, you get to keep both pieces. > Anyway, the procedure that we used (based on > http://en.dklab.ru/lib/dklab_postgresql_enum/) does the necessary > checks before removing enum values. Good. But keep in mind this is not a supported procedure. > ALTER TYPE ... ADD VALUE does not work inside transaction blocks, period, whether they are executed as a multi-command string or one query at a time. Try it: > > begin; > create type test_enum as enum ('ONE', 'TWO'); > alter type test_enum add value 'THREE'; > drop type test_enum; > commit; > > Whether you send the above one query at a time or as a script in psql, it won't work. > > What you call a "minor inconvenience" makes enum management effectively broken, at least in an industrial environment. The reason it is not allowed is because it breaks stuff (I cannot remember what). Inconvenient, yes. "Broken", perhaps. But it's working as designed. If you're interested, you could examine the old threads that led to this behavior and see if it can be improved. But just removing the check won't do. > > restarting the session should do it -- as I said, manipulating pg_enum is > > dangerous. agree with Kevin -- these are not bugs. > > It's weird. Sometimes it works when executing commands in separate transactions. And sometimes the same commands don't work even after restarting Postgresql. Completely unpredictable. > > The reason I regard these issues as bugs is because the new version broke some functionality that worked in the previous version. But if this goes under feature requests, I'll move the discussion over to general. Well, it's perfectly predictable if you constrain yourself to supported operations, which updating catalogs by hand is not. And given that it wasn't supported when this function was written, for 8.3, we have no responsibility for ensuring that it still works in later versions. Note that this email contains no opinion of mine. I am only stating PostgreSQL Global Development Group policy. -- Álvaro Herrera The PostgreSQL Company - Command Prompt, Inc. PostgreSQL Replication, Consulting, Custom Development, 24x7 support