pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Manuel Rigger <rigger.manuel@gmail.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Subject: Re: ALTER TABLE fails when changing column type due to index with bit_ops opclass
Date: Wed, 20 Nov 2019 13:16:22 -0500
Message-ID: <17980.1574273782@sss.pgh.pa.us> (raw)
In-Reply-To: <CA+u7OA4=vs9LjjP_643kgLRENv2eW+8v+5M8QGsY3Sg1K_18fg@mail.gmail.com>
References: <CA+u7OA4=vs9LjjP_643kgLRENv2eW+8v+5M8QGsY3Sg1K_18fg@mail.gmail.com>

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





view thread (3+ messages)  latest in thread

Message-ID: <17980.1574273782@sss.pgh.pa.us>
Permalink:  ../17980.1574273782@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/17980.1574273782@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, rigger.manuel@gmail.com
  Subject: Re: ALTER TABLE fails when changing column type due to index with bit_ops opclass
  In-Reply-To: <17980.1574273782@sss.pgh.pa.us>
  References: <CA+u7OA4=vs9LjjP_643kgLRENv2eW+8v+5M8QGsY3Sg1K_18fg@mail.gmail.com> <17980.1574273782@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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