0

I had a table and I deleted it manually.

Now when I am trying to create it one more time, I am getting next error:

Error: pq: relation "some_table_pkey" already exists

How I can delete this relation?

Next cases don't work:

DROP INDEX IF EXISTS some_table_pkey;

DROP SEQUENCE IF EXISTS some_table_pkey;

P.S. Please don't recommend drop database and restore from dump.

Ted
  • 1,682
  • 3
  • 25
  • 52
  • 1
    Indexes, constraints, views and tables share the same namespace in Postgres. You might have another index, view, constraint or table with that name in your database. –  Jun 14 '21 at 10:29
  • 1
    What do you get for `SELECT oid, relname, relnamespace::regnamespace, relkind FROM pg_class WHERE relname = 'some_table_pkey';`? – Laurenz Albe Jun 14 '21 at 10:47
  • "Don't work" is not an adequate description. Read the error message. If you don't understand it, show it to us and ask about it. – jjanes Jun 14 '21 at 15:26

1 Answers1

1

There will be a primary key with the same table name, try creating a table with serial as the primary key.

CREATE TABLE some_table ( some_table_id serial PRIMARY KEY, col1 integer NOT NULL, col2 integer NOT NULL );

refer:PostgreSQL Error: Relation already exists

Nikhil B
  • 353
  • 2
  • 7