]> begriffs open source - ai-pg/blob - full-docs/html/indexes-unique.html
Include links to all subsection html pages, with shorter paths too
[ai-pg] / full-docs / html / indexes-unique.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>11.6. Unique Indexes</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="indexes-bitmap-scans.html" title="11.5. Combining Multiple Indexes" /><link rel="next" href="indexes-expressional.html" title="11.7. Indexes on Expressions" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">11.6. Unique Indexes</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="indexes-bitmap-scans.html" title="11.5. Combining Multiple Indexes">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="indexes.html" title="Chapter 11. Indexes">Up</a></td><th width="60%" align="center">Chapter 11. Indexes</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="indexes-expressional.html" title="11.7. Indexes on Expressions">Next</a></td></tr></table><hr /></div><div class="sect1" id="INDEXES-UNIQUE"><div class="titlepage"><div><div><h2 class="title" style="clear: both">11.6. Unique Indexes <a href="#INDEXES-UNIQUE" class="id_link">#</a></h2></div></div></div><a id="id-1.5.10.9.2" class="indexterm"></a><p>
3    Indexes can also be used to enforce uniqueness of a column's value,
4    or the uniqueness of the combined values of more than one column.
5 </p><pre class="synopsis">
6 CREATE UNIQUE INDEX <em class="replaceable"><code>name</code></em> ON <em class="replaceable"><code>table</code></em> (<em class="replaceable"><code>column</code></em> [<span class="optional">, ...</span>]) [<span class="optional"> NULLS [<span class="optional"> NOT </span>] DISTINCT </span>];
7 </pre><p>
8    Currently, only B-tree indexes can be declared unique.
9   </p><p>
10    When an index is declared unique, multiple table rows with equal
11    indexed values are not allowed.  By default, null values in a unique column
12    are not considered equal, allowing multiple nulls in the column.  The
13    <code class="literal">NULLS NOT DISTINCT</code> option modifies this and causes the
14    index to treat nulls as equal.  A multicolumn unique index will only reject
15    cases where all indexed columns are equal in multiple rows.
16   </p><p>
17    <span class="productname">PostgreSQL</span> automatically creates a unique
18    index when a unique constraint or primary key is defined for a table.
19    The index covers the columns that make up the primary key or unique
20    constraint (a multicolumn index, if appropriate), and is the mechanism
21    that enforces the constraint.
22   </p><div class="note"><h3 class="title">Note</h3><p>
23     There's no need to manually
24     create indexes on unique columns; doing so would just duplicate
25     the automatically-created index.
26    </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="indexes-bitmap-scans.html" title="11.5. Combining Multiple Indexes">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="indexes.html" title="Chapter 11. Indexes">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="indexes-expressional.html" title="11.7. Indexes on Expressions">Next</a></td></tr><tr><td width="40%" align="left" valign="top">11.5. Combining Multiple Indexes </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 11.7. Indexes on Expressions</td></tr></table></div></body></html>