Re: Attribute has wrong type in ALTER TABLE

From: Manuel Rigger <rigger(dot)manuel(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: Attribute has wrong type in ALTER TABLE
Date: 2019-07-26 22:19:52
Message-ID: CA+u7OA4WD285FfEzcCvjB21OF+JDEEdj_9f5gcvkUC6u26KjUw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Sorry for the duplicate bug report!

In the following test case, the ALTER TABLE seems to result in some
inconsistent database state, which is observed by the subsequent
INSERT:

CREATE TABLE t0(c0 boolean , c1 integer);
ALTER TABLE t0 ADD EXCLUDE (c1 WITH =) WHERE (t0.c0), DROP c0;
INSERT INTO t0(c1) VALUES (0); -- unexpected: ERROR: attribute 1 of
type record has wrong type

I assume it's the same underlying bug, but maybe this could be useful
as an additional test case.

Best,
Manuel

On Wed, Jul 24, 2019 at 8:02 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Manuel Rigger <rigger(dot)manuel(at)gmail(dot)com> 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 =); -- 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_vNcYgKFEoq0WL5GtrBWEHUZnCqSqjhAA%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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2019-07-26 22:20:28 Re: DISCARD TEMP results in "ERROR: cache lookup failed for type 0"
Previous Message Alvaro Herrera 2019-07-26 22:02:42 Re: BUG #15912: The units of `autovacuum_vacuum_cost_delay` setting should be documented