Why do I get the error "unable to encode table key" when altering a table in CockroachDB?

Viewed 11

I'm using CockroachDB version 22.1 and have a table with many columns. When I try to run ALTER TABLE ... DROP COLUMN I get the error ERROR: unable to encode table key: <nil>. How can I fix this?

1 Answers

This is a bug that is fixed in patch 22.1.7, so the easiest way to fix this is to upgrade to that version or higher. It manifests when a table has a virtual column as part of its primary key, which most often happens when using a hash-sharded primary key index.

Related