यह पहले से ही कहा जा चुका है कि पीजी आंशिक (यानी सशर्त) अद्वितीय बाधा परिभाषित नहीं करता है। इसके अलावा प्रलेखन कहते हैं एक मेज के लिए एक अनूठा बाधा जोड़ने के लिए पसंदीदा तरीका 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.
Exclusion Constraints का उपयोग कर इसे लागू करने के लिए एक तरीका नहीं है यह है कि, (इस समाधान के लिए @dukelion धन्यवाद)
आपके मामले में ऐसा लगता है जैसे
ALTER TABLE stop
ADD CONSTRAINT stop_col_a_key_part EXCLUDE (col_a WITH =) WHERE (col_b IS null);
स्रोत
2018-01-11 05:44:01
दिखेगा यह पहले से ही यहाँ जवाब था: http://stackoverflow.com/questions/469471/how-do-i-alter-a-postgresql-table-and-make-a-column- अद्वितीय – yvesonline
आम तौर पर किया गया। "आंशिक अद्वितीय अनुक्रमणिका" –
@yvesonline संख्या देखें, यह एक नियमित अनूठी बाधा है। पोस्टर एक * आंशिक * अद्वितीय बाधा चाहता है। –