On Mon, 2023-11-27 at 08:00 +0800, jian he wrote:
> Hi. minor doc issue.
> create table s1(a int, constraint s2 PRIMARY key (a));
> create table s2(a int);
> ERROR:  relation "s2" already exists
> 
> https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-PARMS-UNIQUE
> maybe for the following 2 sentence
> "Adding a unique constraint will automatically create a unique btree
> index on the column or group of columns used in the constraint."
> "Adding a PRIMARY KEY constraint will automatically create a unique
> btree index on the column or group of columns used in the constraint."
> 
> maybe we can mention that: the unique btree index name will be the
> constraint name.
> also is "a unique" or "an unique"?

It would be "a unique", because "unique" is pronounced "juneek", which
does not start with a vowel.

> I personally thought this part is obscure.

True; I don't find it documented that all objects in pg_class share a
namespace and that constraints are implemented by indexes of the same
name.  But I think that the first part is a property of schemas and had
better be documented there.

What do you think of the attached patch?

Yours,
Laurenz Albe
From dc38339a9348ab4855600f1bbcd79e7712c21780 Mon Sep 17 00:00:00 2001
From: Laurenz Albe <laurenz.a...@cybertec.at>
Date: Mon, 27 Nov 2023 03:25:41 +0100
Subject: [PATCH] Doc: objects in pg_class share a namespace

Explicitly state that tables, indexes, sequences and other relations
share a single namespace.  Also, document that the index that
implements a constraint has the same name as the constraint.
---
 doc/src/sgml/ddl.sgml              | 7 ++++++-
 doc/src/sgml/ref/create_table.sgml | 9 +++++----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index 4490e82aa5..46df1dd344 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -2884,7 +2884,12 @@ SELECT * FROM information WHERE group_id = 2 FOR UPDATE;
   <para>
    A database contains one or more named <firstterm>schemas</firstterm>, which
    in turn contain tables.  Schemas also contain other kinds of named
-   objects, including data types, functions, and operators.  The same
+   objects, including data types, functions, and operators.  Within one schema,
+   two objects of the same type cannot have the same name.  Tables, indexes,
+   sequences (and all other objects stored in
+   <link linkend="catalog-pg-class"><structname>pg_class</structname></link>)
+   share one name space, so they need to have different names if they are in
+   a single schema.  The same
    object name can be used in different schemas without conflict; for
    example, both <literal>schema1</literal> and <literal>myschema</literal> can
    contain tables named <literal>mytable</literal>.  Unlike databases,
diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml
index e04a0692c4..e334b17672 100644
--- a/doc/src/sgml/ref/create_table.sgml
+++ b/doc/src/sgml/ref/create_table.sgml
@@ -1001,7 +1001,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
 
      <para>
       Adding a unique constraint will automatically create a unique btree
-      index on the column or group of columns used in the constraint.
+      index on the column or group of columns used in the constraint.  That
+      index has the same name as the unique constraint.
      </para>
 
      <para>
@@ -1054,7 +1055,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
      <para>
       Adding a <literal>PRIMARY KEY</literal> constraint will automatically
       create a unique btree index on the column or group of columns used in the
-      constraint.
+      constraint.  That index has the same name as the primary key constraint.
      </para>
 
      <para>
@@ -1091,8 +1092,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
 
      <para>
       Exclusion constraints are implemented using
-      an index, so each specified operator must be associated with an
-      appropriate operator class
+      an index that has the same name as the constraint, so each specified
+      operator must be associated with an appropriate operator class
       (see <xref linkend="indexes-opclass"/>) for the index access
       method <replaceable>index_method</replaceable>.
       The operators are required to be commutative.
-- 
2.43.0

Reply via email to