Hi,

Attached is a patch (against head) which documents the
name of the constraint and index created when using
PRIMARY KEY with CREATE TABLE, and the name of the
index created when using UNIQUE.  I haven't read all
the docs recently but I don't believe this is presently
documented.

It's unclear to me that this is the right approach
but perhaps this will start a discussion that finds
the right approach.

The big problem I see is that these are somewhat of
an implementation internal while at the same
time being something that the user might have to
concern themselves with.  

First, the constraint and index
names are in the namespace used by the user so there
is potential for collision with user-defined
constraints and indexes.

Second, the only way (I know of) to remove primary-key-ness
is to drop the primary key constraint, by name.

This lead me right into another thought:
It would be nice to have ALTER TABLE be able to
drop the primary key constraint.  (Then the
user would not need to know the name of the
constraint related to primary-key-ness.)
However, it is probably more useful to be able
to drop the constraint (and attendant foreign
key meta-information) separately from the unique
index associated with the primary key, if for no
other reason than index re-creation can be expensive
and missing indexes make bad things happen.

This patch is the improvement I could come up
with.  Someone else can decide to commit or reject,
I don't believe I can contribute much more on this at this
time.

Regards,

Karl <k...@meme.com>
Free Software:  "You don't pay back, you pay forward."
                 -- Robert A. Heinlein

diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml
index 445ca40..da87574 100644
--- a/doc/src/sgml/ref/create_table.sgml
+++ b/doc/src/sgml/ref/create_table.sgml
@@ -486,6 +486,14 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
       primary key constraint defined for the table.  (Otherwise it
       would just be the same constraint listed twice.)
      </para>
+
+     <para>
+      The name of the index created when <literal>UNIQUE</literal> is
+      used is <literal><replaceable
+      class="PARAMETER">tablename</replaceable>_<replaceable
+      class="PARAMETER">colname</replaceable>_key</literal>.
+     </para>
+
     </listitem>
    </varlistentry>
 
@@ -514,6 +522,13 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
       different from other sets of columns named by any unique
       constraint defined for the same table.
      </para>
+
+     <para>
+       The name of the primary key constraint, and the name of the
+       index which enforces uniqueness, is <literal><replaceable
+       class="PARAMETER">tablename</replaceable>_pkey</literal>.
+     </para>
+
     </listitem>
    </varlistentry>
 

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to