Re: create table explicitly mention that unique|primary key constraint will create an

2024-01-31 Thread Laurenz Albe
On Wed, 2024-01-31 at 12:11 +0100, Peter Eisentraut wrote:
> Sprinkled in some of David's suggestions, and pushed.

Thanks; your text is great.

Yours,
Laurenz Albe




Re: create table explicitly mention that unique|primary key constraint will create an

2024-01-31 Thread Peter Eisentraut

On 18.01.24 22:21, David G. Johnston wrote:
I started looking at this specific item and immediately got the idea to 
actually document in user-facing (i.e., not system catalogs) what these 
object categories are in which object types share the schema namespace. 
The "Other Object Types" section already in the DDL chapter seems to 
provide a near-perfect place to put this (not sure I like the word 
"other" there being my only complaint).  The attached patch replaces 
Laurenz's v1, leaving the create_table changes as-is but presenting an 
alternative approach to introducing namespacing when we explain why 
schemas exist.


I think this proposal goes a bit too far into implementation-dependent 
details.  The namespace of tables and indexes is clearly important, but 
for example, the subdivision of types into range types and multi-range 
types is really low-level and not usually practically relevant.  And you 
don't mention array types, probably because they are not mentioned in 
typtype, but they are also relevant for the namespace of types.  There 
are multiple ways to slice all this, but it's not clear why we need to 
lay this all out in the introductory documentation.






Re: create table explicitly mention that unique|primary key constraint will create an

2024-01-31 Thread Peter Eisentraut

On 26.01.24 16:52, Laurenz Albe wrote:

On Fri, 2024-01-26 at 19:01 +0530, vignesh C wrote:

CFBot shows that the patch does not apply anymore as in [1]:


There was a conflict with 46a0cd4cefb.
Updated version attached.


Sprinkled in some of David's suggestions, and pushed.

I was hesitant to burden the user with the difference between "relation" 
and "table" at this point, so I took the former term out of the text.






Re: create table explicitly mention that unique|primary key constraint will create an

2024-01-26 Thread Laurenz Albe
On Fri, 2024-01-26 at 19:01 +0530, vignesh C wrote:
> CFBot shows that the patch does not apply anymore as in [1]:

There was a conflict with 46a0cd4cefb.
Updated version attached.

Yours,
Laurenz Albe
From 193d6d6c20f0c2976e0b63f1896978545def3fe8 Mon Sep 17 00:00:00 2001
From: Laurenz Albe 
Date: Fri, 26 Jan 2024 16:50:11 +0100
Subject: [PATCH v4] Doc: All relations share a namespace

This was already documented in the CREATE INDEX reference,
but not in the introductory "Data Definition" chapter.
Also, document that the index that implements a constraint
has the same name as the constraint.

Author: Laurenz Albe
Reviewed-by: Jian He, Peter Eisentraut, David G. Johnston
Discussion: https://postgr.es/m/CACJufxFG682tYcP9aH_F-jrqq5End8MHZR77zcp1%3DDUrEsSu1Q%40mail.gmail.com
---
 doc/src/sgml/ddl.sgml  | 6 +-
 doc/src/sgml/ref/create_table.sgml | 8 +---
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index fc03a349f0..434e074df1 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -3003,7 +3003,11 @@ SELECT * FROM information WHERE group_id = 2 FOR UPDATE;
   
A database contains one or more named schemas, 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.  All relations
+   (tables, sequences, indexes, views, materialized views, and foreign tables)
+   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 schema1 and myschema can
contain tables named mytable.  Unlike databases,
diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml
index 079af9126a..bdc3541930 100644
--- a/doc/src/sgml/ref/create_table.sgml
+++ b/doc/src/sgml/ref/create_table.sgml
@@ -1027,7 +1027,8 @@ WITH ( MODULUS numeric_literal, REM
   Adding a unique constraint will automatically create a unique B-tree
   index on the column or group of columns used in the constraint.  But if
   the constraint includes a WITHOUT OVERLAPS clause, it
-  will use a GiST index.
+  will use a GiST index.  The created index has the same name as the unique
+  constraint.
  
 
  
@@ -1082,6 +1083,7 @@ WITH ( MODULUS numeric_literal, REM
   PRIMARY KEY constraint will automatically create a
   unique B-tree index, or GiST if WITHOUT OVERLAPS was
   specified, on the column or group of columns used in the constraint.
+  That index has the same name as the primary key constraint.
  
 
  
@@ -1118,8 +1120,8 @@ WITH ( MODULUS numeric_literal, REM
 
  
   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 ) for the index access
   method index_method.
   The operators are required to be commutative.
-- 
2.43.0



Re: create table explicitly mention that unique|primary key constraint will create an

2024-01-26 Thread David G. Johnston
On Fri, Jan 19, 2024 at 3:46 AM Laurenz Albe 
wrote:

> In the attached patch, I have copied the enumeration of relations from
> the CREATE INDEX page.  I think this small redundance is alright, but I
> wouldn't mind if this gets removed from CREATE INDEX.
>
>
Tweaking the main paragraph a little.

We use examples elsewhere, it seems one for this makes the point very clear
with less description.

I removed it altogether but namespace is a word unto itself, not "name
space".

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index e103eddd40..25db985a56 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -3025,10 +3025,11 @@ SELECT * FROM information WHERE group_id = 2 FOR
UPDATE;
A database contains one or more named schemas,
which
in turn contain tables.  Schemas also contain other kinds of named
objects, including data types, functions, and operators.  Within one
schema,
-   two objects of the same type cannot have the same name.  All relations
-   (tables, sequences, indexes, views, materialized views, and foreign
tables)
-   share one name space, so they need to have different names if they are
in
-   a single schema.  The same
+   two objects of the same type cannot have the same name.  The object type
+   of relations encompasses all of the following:
+   tables, sequences, indexes, views, materialized views, and foreign
tables.
+   Thus, for example, an index and a table must have different names if
they
+   are in the same schema.  The same
object name can be used in different schemas without conflict; for
example, both schema1 and
myschema can
contain tables named mytable.  Unlike databases,

David J.


Re: create table explicitly mention that unique|primary key constraint will create an

2024-01-26 Thread vignesh C
On Fri, 19 Jan 2024 at 16:16, Laurenz Albe  wrote:
>
> On Thu, 2024-01-18 at 15:54 +0100, Peter Eisentraut wrote:
> > On 27.11.23 03:30, Laurenz Albe wrote:
> > > 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.
> >
> > It is documented prominently on the CREATE INDEX reference page.  We
> > could document it in more places, of course.  I find the specific change
> > proposal for ddl.sgml a bit weird, though, because this is a very
> > introductory section, and you are referring people to pg_class (what is
> > that?!?) for details.  If we want to put something there, it should
> > respect the order in which that chapter introduces concepts.
> >
> > The changes on create_table.sgml seem ok.  Although I had actually
> > expected that the system applies the find-a-unique-name routine rather
> > than taking the constraint name for the index name unaltered.
> >
> > Perhaps taking the create_table.sgml changes and combination with the
> > existing text on CREATE INDEX is sufficient.
>
> Ah, I didn't see the CREATE INDEX page.  (As an aside: too much
> conceptual stuff is documented in our reference pages, but that's a
> different issue.)
>
> For me, the intuitive place to look for information like that is the
> "Data Definition" chapter, so I think we should mention it there.
> I agree that "pg_class" is too advanced for that chapter, even though
> there is an earlier reference to it under "System Columns".
>
> In the attached patch, I have copied the enumeration of relations from
> the CREATE INDEX page.  I think this small redundance is alright, but I
> wouldn't mind if this gets removed from CREATE INDEX.
>
> The rest is unmodified.

CFBot shows that the patch does not apply anymore as in [1]:
=== Applying patches on top of PostgreSQL commit ID
d282e88e50521a457fa1b36e55f43bac02a3167f ===
=== applying patch ./v3-0001-Doc-All-relations-share-a-namespace.patch
...
patching file doc/src/sgml/ref/create_table.sgml
Hunk #1 FAILED at 1001.
Hunk #2 FAILED at 1054.
Hunk #3 succeeded at 1118 (offset 27 lines).
2 out of 3 hunks FAILED -- saving rejects to file
doc/src/sgml/ref/create_table.sgml.rej

Please post an updated version for the same.

[1] - http://cfbot.cputube.org/patch_46_4747.log

Regards,
Vignesh




Re: create table explicitly mention that unique|primary key constraint will create an

2024-01-19 Thread Laurenz Albe
On Thu, 2024-01-18 at 15:54 +0100, Peter Eisentraut wrote:
> On 27.11.23 03:30, Laurenz Albe wrote:
> > 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.
> 
> It is documented prominently on the CREATE INDEX reference page.  We 
> could document it in more places, of course.  I find the specific change 
> proposal for ddl.sgml a bit weird, though, because this is a very 
> introductory section, and you are referring people to pg_class (what is 
> that?!?) for details.  If we want to put something there, it should 
> respect the order in which that chapter introduces concepts.
> 
> The changes on create_table.sgml seem ok.  Although I had actually 
> expected that the system applies the find-a-unique-name routine rather 
> than taking the constraint name for the index name unaltered.
> 
> Perhaps taking the create_table.sgml changes and combination with the 
> existing text on CREATE INDEX is sufficient.

Ah, I didn't see the CREATE INDEX page.  (As an aside: too much
conceptual stuff is documented in our reference pages, but that's a
different issue.)

For me, the intuitive place to look for information like that is the
"Data Definition" chapter, so I think we should mention it there.
I agree that "pg_class" is too advanced for that chapter, even though
there is an earlier reference to it under "System Columns".

In the attached patch, I have copied the enumeration of relations from
the CREATE INDEX page.  I think this small redundance is alright, but I
wouldn't mind if this gets removed from CREATE INDEX.

The rest is unmodified.

Yours,
Laurenz Albe
From b85ccf59ad0575e5040b17bbed5d2e152217df47 Mon Sep 17 00:00:00 2001
From: Laurenz Albe 
Date: Fri, 19 Jan 2024 11:37:32 +0100
Subject: [PATCH v3] Doc: All relations share a namespace

This was already documented in the CREATE INDEX reference,
but not in the introductory "Data Definition" chapter.
Also, document that the index that implements a constraint
has the same name as the constraint.

Author: Laurenz Albe
Reviewed-by: Jian He, Peter Eisentraut, David G. Johnston
Discussion: https://postgr.es/m/CACJufxFG682tYcP9aH_F-jrqq5End8MHZR77zcp1%3DDUrEsSu1Q%40mail.gmail.com
---
 doc/src/sgml/ddl.sgml  | 6 +-
 doc/src/sgml/ref/create_table.sgml | 9 +
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index 4044f0908f..13831667fe 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -3001,7 +3001,11 @@ SELECT * FROM information WHERE group_id = 2 FOR UPDATE;
   
A database contains one or more named schemas, 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.  All relations
+   (tables, sequences, indexes, views, materialized views, and foreign tables)
+   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 schema1 and myschema can
contain tables named mytable.  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 numeric_literal, REM
 
  
   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.
  
 
  
@@ -1054,7 +1055,7 @@ WITH ( MODULUS numeric_literal, REM
  
   Adding a PRIMARY KEY 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.
  
 
  
@@ -1091,8 +1092,8 @@ WITH ( MODULUS numeric_literal, REM
 
  
   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 ) for the index access
   method index_method.
   The operators are required to be commutative.
-- 
2.43.0



Re: create table explicitly mention that unique|primary key constraint will create an

2024-01-18 Thread David G. Johnston
On Thu, Jan 18, 2024 at 7:54 AM Peter Eisentraut 
wrote:

>
> I find the specific change
> proposal for ddl.sgml a bit weird, though, because this is a very
> introductory section, and you are referring people to pg_class (what is
> that?!?) for details.  If we want to put something there, it should
> respect the order in which that chapter introduces concepts.
>
>
I started looking at this specific item and immediately got the idea to
actually document in user-facing (i.e., not system catalogs) what these
object categories are in which object types share the schema namespace.
The "Other Object Types" section already in the DDL chapter seems to
provide a near-perfect place to put this (not sure I like the word "other"
there being my only complaint).  The attached patch replaces Laurenz's v1,
leaving the create_table changes as-is but presenting an alternative
approach to introducing namespacing when we explain why schemas exist.

David J.
From 4ba026d1a42e074df103a769e0f6b71629631c87 Mon Sep 17 00:00:00 2001
From: "David G. Johnston" 
Date: Thu, 18 Jan 2024 14:15:33 -0700
Subject: [PATCH] Doc-objects-in-pg_class-share-a-namespace

---
 doc/src/sgml/ddl.sgml  | 168 +++--
 doc/src/sgml/ref/create_table.sgml |   9 +-
 2 files changed, 163 insertions(+), 14 deletions(-)

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index fc03a349f0..86f793f724 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -3002,11 +3002,18 @@ SELECT * FROM information WHERE group_id = 2 FOR UPDATE;
 
   
A database contains one or more named schemas, which
-   in turn contain tables.  Schemas also contain other kinds of named
-   objects, including data types, functions, and operators.  The same
-   object name can be used in different schemas without conflict; for
-   example, both schema1 and myschema can
-   contain tables named mytable.  Unlike databases,
+   in turn contain all other database-specific objects (most importantly, tables).
+   The schema name, combined with an object's type category (i.e., tables are relationas),
+   forms a namespace in which any given object's name exists.
+   When writing an object's name the object type category component is inferred from
+   context.  The schema name component can be explicitly prepended to the name separated
+   by a period (e.g., schema.object_name).  If the schema name is not specified, the system
+   will search for the name in the schemas named in the search_path setting.
+   See ... for a listing of object types grouped by category.
+  
+
+  
+   Unlike databases,
schemas are not rigidly separated: a user can access objects in any
of the schemas in the database they are connected to, if they have
privileges to do so.
@@ -5274,31 +5281,172 @@ EXPLAIN SELECT count(*) FROM measurement WHERE logdate = DATE '2008-01-01';
that exist in a database.  Many other kinds of objects can be
created to make the use and management of the data more efficient
or convenient.  They are not discussed in this chapter, but we give
-   you a list here so that you are aware of what is possible:
+   you a partial list here so that you are aware of what is possible.
+   The first tier of labels are the object type categories that combine
+   with the schema name to form a namespace.  If multiple specific
+   object types share the same category they will be listed in the
+   second tier of labels.
   
 
   

 
- Views
+ Relations
+
+
+ 
+  
+   
+Tables
+   
+  
+  
+   
+Indexes
+   
+  
+  
+   
+Views
+   
+  
+  
+   
+Materialized Views
+   
+  
+  
+   
+Foreign Tables
+   
+  
+  
+   
+Composite Types
+   
+  
+  
+   
+Sequences
+   
+  
+  
+   
+Partitioned Tables
+   
+  
+  
+   
+Partitioned Indexes
+   
+  
+ 
+
+   
+
+   
+
+ Routines
+
+
+ 
+  
+   
+Functions
+   
+  
+  
+   
+Aggregate Functions
+   
+  
+  
+   
+Window Functions
+   
+  
+  
+   
+Procedures
+   
+  
+ 
+
+   
+
+   
+
+ Data Types
+
+
+ 
+  
+   
+Base Types
+   
+  
+  
+   
+Composite Types
+   
+  
+  
+   
+Range Types
+   
+  
+  
+   
+Multi-Range Types
+   
+  
+  
+   
+Domains
+   
+  
+  
+   
+Enums
+   
+  
+ 
+
+   
+
+   
+
+ Operators
+
+   
+
+   
+
+ Triggers
+
+   
+
+   
+
+ Row-Level Security (RLS) Policies
 

 

 
- Functions, procedures, and operators
+ Text Search Dictionaries
 

 

 
-

Re: create table explicitly mention that unique|primary key constraint will create an

2024-01-18 Thread Peter Eisentraut

On 27.11.23 03:30, Laurenz Albe wrote:

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.


It is documented prominently on the CREATE INDEX reference page.  We 
could document it in more places, of course.  I find the specific change 
proposal for ddl.sgml a bit weird, though, because this is a very 
introductory section, and you are referring people to pg_class (what is 
that?!?) for details.  If we want to put something there, it should 
respect the order in which that chapter introduces concepts.


The changes on create_table.sgml seem ok.  Although I had actually 
expected that the system applies the find-a-unique-name routine rather 
than taking the constraint name for the index name unaltered.


Perhaps taking the create_table.sgml changes and combination with the 
existing text on CREATE INDEX is sufficient.






Re: create table explicitly mention that unique|primary key constraint will create an

2023-11-26 Thread jian he
On Mon, Nov 27, 2023 at 10:30 AM Laurenz Albe  wrote:
>
> What do you think of the attached patch?
>
> Yours,
> Laurenz Albe

looks good to me.




Re: create table explicitly mention that unique|primary key constraint will create an

2023-11-26 Thread Laurenz Albe
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 
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;
   
A database contains one or more named schemas, 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
+   pg_class)
+   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 schema1 and myschema can
contain tables named mytable.  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 numeric_literal, REM
 
  
   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.
  
 
  
@@ -1054,7 +1055,7 @@ WITH ( MODULUS numeric_literal, REM
  
   Adding a PRIMARY KEY 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.
  
 
  
@@ -1091,8 +1092,8 @@ WITH ( MODULUS numeric_literal, REM
 
  
   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 ) for the index access
   method index_method.
   The operators are required to be commutative.
-- 
2.43.0



create table explicitly mention that unique|primary key constraint will create an

2023-11-26 Thread jian he
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"?
I personally thought this part is obscure.