Home > Software engineering >  How can I "add constraint *index name* unique ((case...))" in PostgreSQL?
How can I "add constraint *index name* unique ((case...))" in PostgreSQL?

Time:11-09

I'm try to bring all index creations to the same style. This article says that add constraint ... unique better than create index unique. And now I have a problem with indexes that contains ((case ...)). Can I use add constraint ... unique for this?

CodePudding user response:

Different from indexes, constraints can only be defined on columns, not on expressions. So if you need to enforce uniqueness on expressions, you have to CREATE UNIQUE INDEX.

  • Related