pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
ALTER TABLE fails when changing column type due to index with bit_ops opclass
3+ messages / 2 participants
[nested] [flat]

* ALTER TABLE fails when changing column type due to index with bit_ops opclass
@ 2019-11-20 12:42 Manuel Rigger <rigger.manuel@gmail.com>
  2019-11-20 18:16 ` Re: ALTER TABLE fails when changing column type due to index with bit_ops opclass Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Manuel Rigger @ 2019-11-20 12:42 UTC (permalink / raw)
  To: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

Hi everyone,

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 can reproduce this on a recent trunk
version (b3c265d).

Best,
Manuel





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: ALTER TABLE fails when changing column type due to index with bit_ops opclass
  2019-11-20 12:42 ALTER TABLE fails when changing column type due to index with bit_ops opclass Manuel Rigger <rigger.manuel@gmail.com>
@ 2019-11-20 18:16 ` Tom Lane <tgl@sss.pgh.pa.us>
  2019-11-25 20:22   ` Re: ALTER TABLE fails when changing column type due to index with bit_ops opclass Manuel Rigger <rigger.manuel@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2019-11-20 18:16 UTC (permalink / raw)
  To: Manuel Rigger <rigger.manuel@gmail.com>; +Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

Manuel Rigger <rigger.manuel@gmail.com> 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





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: ALTER TABLE fails when changing column type due to index with bit_ops opclass
  2019-11-20 12:42 ALTER TABLE fails when changing column type due to index with bit_ops opclass Manuel Rigger <rigger.manuel@gmail.com>
  2019-11-20 18:16 ` Re: ALTER TABLE fails when changing column type due to index with bit_ops opclass Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-11-25 20:22   ` Manuel Rigger <rigger.manuel@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Manuel Rigger @ 2019-11-25 20:22 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

I see, thanks for the explanation!



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2019-11-25 20:22 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-11-20 12:42 ALTER TABLE fails when changing column type due to index with bit_ops opclass Manuel Rigger <rigger.manuel@gmail.com>
2019-11-20 18:16 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-11-25 20:22   ` Manuel Rigger <rigger.manuel@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox