Hello,

The attached patch updates the docs about defining keys. It more
explicitly recommends using a primary key, and provides an example
syntax to convert a unique/not null index to a primary key.

The essence of the patch has been text-ified below for easier
peer review of grammar and accuracy.

    Mark

....

If the table hasn't got a primary key, but has some
<em>candidate</em> primary key, that is, some index on a
combination of fields that is both UNIQUE and NOT NULL, then you can
specify the key, as in the example below.

 SET ADD TABLE (set id = 1, origin = 1, id = 42,
                full qualified name = 'public.this_table',
                key = 'this_by_that',
      comment='this_table has this_by_that as a candidate primary key');

HOWEVER, once you have gotten this far, there is little reason not to
just convert the index to be a primary key instead, which also implies
that the columns involved be NOT NULL, and will create a unique index.
Here's an example conversion:

 DROP INDEX my_table_name_col1_col2_uniq_idx;
 ALTER TABLE my_table_name ADD PRIMARY KEY (col1, col2);

If your application is not using the index by name,
the effective result should be the same, with the added value that
a primary key has been declared.
--- old-slony1-1.2.5/doc/adminguide/defineset.sgml      2007-01-25 14:59:43.000000000 -0500
+++ new-slony1-1.2.5/doc/adminguide/defineset.sgml      2007-01-25 14:59:43.000000000 -0500
@@ -42,7 +42,7 @@
 <listitem><para> If the table hasn't got a primary key, but has some
 <emphasis>candidate</emphasis> primary key, that is, some index on a
 combination of fields that is both UNIQUE and NOT NULL, then you can
-specify the key, as in</para>
+specify the key, as in the example below. </para>

 <programlisting>
 SET ADD TABLE (set id = 1, origin = 1, id = 42,
@@ -51,6 +51,22 @@
      comment='this_table has this_by_that as a candidate primary key');
 </programlisting>

+<para> HOWEVER, once you have gotten
+this far, there is little reason not to just convert the index to be
+a primary key instead, which also implies that the columns involved
+be NOT NULL, and will create a unique index. Here's an example conversion:
+</para>
+
+<programlisting>
+DROP INDEX my_table_name_col1_col2_uniq_idx;
+ALTER TABLE my_table_name ADD PRIMARY KEY (col1, col2);
+</programlisting>
+
+<para>If your application is not using the index by name,
+the effective result should be the same, with the added value that
+a primary key has been declared.
+  </para>
+
 <para> Notice that while you need to specify the namespace for the
 table, you must <emphasis>not</emphasis> specify the namespace for the
 key, as it infers the namespace from the table.</para></listitem>
_______________________________________________
Slony1-general mailing list
[email protected]
http://gborg.postgresql.org/mailman/listinfo/slony1-general

Reply via email to