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 1hqLax-0003pA-M1 for pgsql-bugs@arkaria.postgresql.org; Wed, 24 Jul 2019 18:02:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hqLaw-0008G7-HI for pgsql-bugs@arkaria.postgresql.org; Wed, 24 Jul 2019 18:02:30 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hqLaw-0008F4-9s for pgsql-bugs@lists.postgresql.org; Wed, 24 Jul 2019 18:02:30 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hqLat-0004eM-7B for pgsql-bugs@lists.postgresql.org; Wed, 24 Jul 2019 18:02:29 +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 x6OI2Npw000519; Wed, 24 Jul 2019 14:02:23 -0400 From: Tom Lane To: Manuel Rigger cc: PostgreSQL mailing lists Subject: Re: Attribute has wrong type in ALTER TABLE In-reply-to: References: Comments: In-reply-to Manuel Rigger message dated "Wed, 24 Jul 2019 09:16:32 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <517.1563991343.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 24 Jul 2019 14:02:23 -0400 Message-ID: <518.1563991343@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Manuel Rigger writes: > the statements below result in an error "ERROR: attribute 1 of type > t0 has wrong type": > CREATE TABLE t0(c0 VARCHAR(10)); > INSERT INTO t0(c0) VALUES(''); > ALTER TABLE t0 ALTER c0 SET DATA TYPE TEXT, ADD EXCLUDE (('a' LIKE > t0.c0) WITH =3D); -- unexpected: ERROR: attribute 1 of type t0 has > wrong type Yeah, this is another variant of the problems with doing transformIndexStmt too early, like your previous report https://www.postgresql.org/message-id/CA%2Bu7OA4hkFSV_Y%3DsW_vNcYgKFEoq0WL= 5GtrBWEHUZnCqSqjhAA%40mail.gmail.com The index expression is parse-analyzed while c0 is still varchar, and then it's wrong by the time we go to create the index. We need to fix things so that ALTER TABLE doesn't do any of that work until after it's finished with ALTER COLUMN TYPE subcommands. regards, tom lane