File tree 1 file changed +19
-0
lines changed
1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -662,6 +662,15 @@ CREATE INDEX test1_lower_col1_idx ON test1 (lower(col1));
662
662
</programlisting>
663
663
</para>
664
664
665
+ <para>
666
+ Expression indexes also allow control over the scope of unique indexes.
667
+ For example, this unique index prevents duplicate integer values from
668
+ being stored in a <type>double precision</type>-typed column:
669
+ <programlisting>
670
+ CREATE UNIQUE INDEX test1_uniq_int ON tests ((floor(double_col)))
671
+ </programlisting>
672
+ </para>
673
+
665
674
<para>
666
675
If we were to declare this index <literal>UNIQUE</>, it would prevent
667
676
creation of rows whose <literal>col1</> values differ only in case,
@@ -901,6 +910,16 @@ CREATE UNIQUE INDEX tests_success_constraint ON tests (subject, target)
901
910
This is a particularly efficient approach when there are few
902
911
successful tests and many unsuccessful ones.
903
912
</para>
913
+
914
+ <para>
915
+ This index allows only one null in the indexed column by using a
916
+ partial index clause to process only null column values, and using
917
+ an expression index clause to index <literal>true</literal> instead
918
+ of <literal>null</literal>:
919
+ <programlisting>
920
+ CREATE UNIQUE INDEX tests_target_one_null ON tests ((target IS NULL)) WHERE target IS NULL;
921
+ </programlisting>
922
+ </para>
904
923
</example>
905
924
906
925
<para>
You can’t perform that action at this time.
0 commit comments