Es wurde bereits gesagt, dass PG keine partielle (dh bedingte) UNIQUE-Einschränkung definiert. Auch sagt Dokumentation, dass der bevorzugte Weg, um eine eindeutige Einschränkung auf eine Tabelle hinzuzufügen, ist ADD CONSTRAINT
Unique Indexes
The preferred way to add a unique constraint to a table is ALTER TABLE ... ADD CONSTRAINT. The use of indexes to enforce unique constraints could be considered an implementation detail that should not be accessed directly. One should, however, be aware that there's no need to manually create indexes on unique columns; doing so would just duplicate the automatically-created index.
Es gibt einen Weg, es zu implementieren ist Exclusion Constraints Verwendung
In Ihrem Fall (@dukelion für diese Lösung danken) es wie
ALTER TABLE stop
ADD CONSTRAINT stop_col_a_key_part EXCLUDE (col_a WITH =) WHERE (col_b IS null);
aussehen
Dies wurde bereits hier beantwortet: http://stackoverflow.com/questions/469471/how-do-i-alter-a-postgresql-table-and-make-a-column- einzigartig – yvesonline
Häufig gemacht. Siehe "teilweise eindeutiger Index" –
@yvesonline nein, das ist eine reguläre eindeutige Einschränkung. Das Poster möchte eine * partielle * eindeutige Einschränkung. –