3

Why DuckDB tells me there is no column named that way when I try to drop a column?

D DESCRIBE oa_pub;
┌──────────────┬─────────────┬─────────┬─────────┬──────────────────────────┬─────────┐
│ column_name  │ column_type │  null   │   key   │         default          │  extra  │
│   varchar    │   varchar   │ varchar │ varchar │         varchar          │ varchar │
├──────────────┼─────────────┼─────────┼─────────┼──────────────────────────┼─────────┤
│ id           │ INTEGER     │ NO      │ PRI     │ nextval('oa_pub_id_seq') │ NULL    │
│ project_id   │ INTEGER     │ NO      │ UNI     │ NULL                     │ NULL    │
│ oa_author_id │ VARCHAR     │ NO      │ UNI     │ NULL                     │ NULL    │
│ oa_pub_id    │ VARCHAR     │ NO      │ UNI     │ NULL                     │ NULL    │
│ oa_pub_json  │ JSON        │ YES     │ NULL    │ NULL                     │ NULL    │
│ oa_pub_id_2  │ VARCHAR     │ YES     │ NULL    │ NULL                     │ NULL    │
└──────────────┴─────────────┴─────────┴─────────┴──────────────────────────┴─────────┘
D ALTER TABLE oa_pub DROP COLUMN oa_pub_id;
Catalog Error:
table "oa_pub" does not have a column named oa_pub_id
2
  • Is it possible the oa_pub_id column name contains trailing whitespace? e.g. SET colname = ' oa_pub_id '; Commented Jun 16 at 18:06
  • @Dai that came to me also but it's not that. See my answer. But thank you very much for the help indeed! Commented Jun 16 at 18:09

1 Answer 1

3

Although the error message is cryptic, the problem was that oa_pub_id is part of a unique constraint. See the key column of the table returned by DESCRIBE.

To reproduce:

D CREATE TABLE test2 (id INT PRIMARY KEY, name TEXT, surname TEXT, age INT, UNIQUE(surname, age));
D DESCRIBE test2;
┌─────────────┬─────────────┬─────────┬─────────┬─────────┬─────────┐
│ column_name │ column_type │  null   │   key   │ default │  extra  │
│   varchar   │   varchar   │ varchar │ varchar │ varchar │ varchar │
├─────────────┼─────────────┼─────────┼─────────┼─────────┼─────────┤
│ id          │ INTEGER     │ NO      │ PRI     │ NULL    │ NULL    │
│ name        │ VARCHAR     │ YES     │ NULL    │ NULL    │ NULL    │
│ surname     │ VARCHAR     │ YES     │ UNI     │ NULL    │ NULL    │
│ age         │ INTEGER     │ YES     │ UNI     │ NULL    │ NULL    │
└─────────────┴─────────────┴─────────┴─────────┴─────────┴─────────┘
D ALTER TABLE test2 DROP COLUMN surname;
Catalog Error:
table "test2" does not have a column named "surname"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.