Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iXUWo-0004SQ-Rc for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Nov 2019 18:16:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iXUWj-0004PC-Vi for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Nov 2019 18:16:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iXUWj-0004Oz-Ju for pgsql-bugs@lists.postgresql.org; Wed, 20 Nov 2019 18:16:29 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iXUWg-00034N-FP for pgsql-bugs@lists.postgresql.org; Wed, 20 Nov 2019 18:16:27 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id xAKIGMFW017981; Wed, 20 Nov 2019 13:16:22 -0500 From: Tom Lane To: Manuel Rigger cc: PostgreSQL mailing lists Subject: Re: ALTER TABLE fails when changing column type due to index with bit_ops opclass In-reply-to: References: Comments: In-reply-to Manuel Rigger message dated "Wed, 20 Nov 2019 13:42:30 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <17979.1574273782.1@sss.pgh.pa.us> Date: Wed, 20 Nov 2019 13:16:22 -0500 Message-ID: <17980.1574273782@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Manuel Rigger writes: > Consider the following statements: > CREATE TABLE t0(c0 BIT VARYING(1)); > CREATE INDEX i0 ON t0(c0 bit_ops); > ALTER TABLE t0 ALTER c0 TYPE TEXT; -- ERROR: operator class "bit_ops" > does not accept data type text > Altering the column type fails, which is somewhat unexpected, since it > does not seem to cause problems for other opclasses. For example, the > following executes without errors: > CREATE TABLE t0(c0 TEXT); > CREATE INDEX i0 ON t0(c0 text_ops); > ALTER TABLE t0 ALTER c0 TYPE BIT VARYING(1) USING c0::bit varying(1); > Is this a bug or expected? I think this is expected behavior, more or less. The critical difference is that you specified a non-default opclass in the first example (the default choice for that column datatype is varbit_ops not bit_ops). ALTER TABLE figures that it's okay to replace the default opclass for the original type with the default opclass for the new type, but it's not willing to guess about what you want if the index has a non-default opclass. So the conversion only goes through if the specified opclass also accepts the new datatype, which typically it wouldn't. This is probably not documented anyplace. Should it be? If so, what should we say and where? regards, tom lane