is it possible to create unique constrain in Postgresql, that would take into account column values and work with some value, but not with another?
I have table, where items have "code" that must be unique, but records aren't deleted from table, just marked as deleted (special boolean field "deleted"). I could create unique(code, deleted) to enforce uniqueness, it works if I don't mark 2 rows as deleted with same "code". If I would try to "delete" second row, it will alert that 2 rows will have same unique values and doesn't allow.
What I would like to have, is check unique field "code" for every row, that "deleted" is false.