Mark Stosberg mark
Thu Jan 25 12:06:39 PST 2007
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: definesets.patch
Type: text/x-patch
Size: 1461 bytes
Desc: not available
Url : http://gborg.postgresql.org/pipermail/slony1-general/attachments/20070125/f037d55b/attachment.bin 



More information about the Slony1-general mailing list