Re: Converting non-null unique idx to pkey - Mailing list pgsql-general

From Tom Lane
Subject Re: Converting non-null unique idx to pkey
Date
Msg-id 2467.1187761230@sss.pgh.pa.us
Whole thread Raw
In response to Converting non-null unique idx to pkey  ("Ed L." <pgsql@bluepolka.net>)
Responses Re: Converting non-null unique idx to pkey  ("Ed L." <pgsql@bluepolka.net>)
List pgsql-general
"Ed L." <pgsql@bluepolka.net> writes:
> Are there
> are any known or obvious gotchas associated with transforming a
> unique index on a non null column into a primary key via this
> sql?

> update pg_index
> set indisprimary = 't'
> where indexrelid = <my non-null unique index oid>

The problem with that is there won't be any pg_constraint entry,
nor any pg_depend entries linking to/from the constraint.

I don't offhand know which bits of logic look at indisprimary
and which pay attention to the pg_constraint entry (and 7.4 is
probably different from current sources on the point anyway).
Things could get a bit weird though, particularly for pg_dump.

Of course, you could gin up the required pg_constraint and pg_depend
entries by hand too, but it's a lot more complex than the above.

If you really wanna do this I'd strongly recommend experimenting
in a scratch database.

            regards, tom lane

pgsql-general by date:

Previous
From: "Robin Helgelin"
Date:
Subject: Re: history table
Next
From: "Frank Millman"
Date:
Subject: Problem with UPDATE and UNIQUE