From: Laurenz Albe <laurenz.albe@cybertec.at>
To: jian he <jian.universality@gmail.com>
To: pgsql-docs@lists.postgresql.org
Subject: Re: create table explicitly mention that unique|primary key constraint will create an
Date: Mon, 27 Nov 2023 03:30:28 +0100
Message-ID: <24f01200b651ff87311ae0f46b99eaf91fc3ec43.camel@cybertec.at> (raw)
In-Reply-To: <CACJufxFG682tYcP9aH_F-jrqq5End8MHZR77zcp1=DUrEsSu1Q@mail.gmail.com>
References: <CACJufxFG682tYcP9aH_F-jrqq5End8MHZR77zcp1=DUrEsSu1Q@mail.gmail.com>
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
Attachments:
[text/x-patch] 0001-Doc-objects-in-pg_class-share-a-namespace.patch (3.2K, ../24f01200b651ff87311ae0f46b99eaf91fc3ec43.camel@cybertec.at/2-0001-Doc-objects-in-pg_class-share-a-namespace.patch)
download | inline diff:
From dc38339a9348ab4855600f1bbcd79e7712c21780 Mon Sep 17 00:00:00 2001
From: Laurenz Albe <laurenz.albe@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.sgmlindex 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.sgmlindex 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 instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-docs@postgresql.org
Cc: laurenz.albe@cybertec.at, jian.universality@gmail.com, pgsql-docs@lists.postgresql.org
Subject: Re: create table explicitly mention that unique|primary key constraint will create an
In-Reply-To: <24f01200b651ff87311ae0f46b99eaf91fc3ec43.camel@cybertec.at>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox