DEV Community

Lang Sharpe
Lang Sharpe

Posted on

2

Creating indexes in PostgreSQL isn't always idempotent

Usually, when you call CREATE INDEX in Postgres, you expect the index to be created, or an error to be raised. However, if you are doing each of these:-

  • Creating a UNIQUE index
  • The data is not unique
  • Creating the index CONCURRENTLY

An index will be created, but be INVALID. From the documentation:-

If a problem arises while scanning the table, such as a deadlock or a uniqueness violation in a unique index, the CREATE INDEX command will fail but leave behind an “invalid” index.

Source

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay