File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -710,6 +710,15 @@ CREATE INDEX test1_lower_col1_idx ON test1 (lower(col1));
710
710
</programlisting>
711
711
</para>
712
712
713
+ <para>
714
+ Expression indexes also allow control over the scope of unique indexes.
715
+ For example, this unique index prevents duplicate integer values from
716
+ being stored in a <type>double precision</type>-typed column:
717
+ <programlisting>
718
+ CREATE UNIQUE INDEX test1_uniq_int ON tests ((floor(double_col)))
719
+ </programlisting>
720
+ </para>
721
+
713
722
<para>
714
723
If we were to declare this index <literal>UNIQUE</>, it would prevent
715
724
creation of rows whose <literal>col1</> values differ only in case,
@@ -949,6 +958,16 @@ CREATE UNIQUE INDEX tests_success_constraint ON tests (subject, target)
949
958
This is a particularly efficient approach when there are few
950
959
successful tests and many unsuccessful ones.
951
960
</para>
961
+
962
+ <para>
963
+ This index allows only one null in the indexed column by using a
964
+ partial index clause to process only null column values, and using
965
+ an expression index clause to index <literal>true</literal> instead
966
+ of <literal>null</literal>:
967
+ <programlisting>
968
+ CREATE UNIQUE INDEX tests_target_one_null ON tests ((target IS NULL)) WHERE target IS NULL;
969
+ </programlisting>
970
+ </para>
952
971
</example>
953
972
954
973
<para>
You can’t perform that action at this time.
0 commit comments