vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi all. I'd need to modify the primary key definition in an already populated table. How can I do it? Thanks. ---------------------------(end of broadcast)--------------------------- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq |
| |||
| -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 10/26/07 04:39, Reg Me Please wrote: > Hi all. > I'd need to modify the primary key definition in an already populated table. > How can I do it? Have you tried dropping the constraint, and creating a new one? http://www.postgresql.org/docs/8.2/i...ltertable.html - -- Ron Johnson, Jr. Jefferson LA USA Give a man a fish, and he eats for a day. Hit him with a fish, and he goes away for good! -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFHIbwhS9HxQb37XmcRAjg6AJ4sPW7wPH599JPVdmZ5s2 5b5yHnHQCeJtsr 0TRv9XcYy2+04FW+1dNIYFc= =ldEW -----END PGP SIGNATURE----- ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster |
| ||||
| On Oct 26, 2007, at 5:39 , Reg Me Please wrote: > I'd need to modify the primary key definition in an already > populated table. > How can I do it? Drop the primary key constraint and create a new one. You can do this inside a transaction. test=# \d strings Table "public.strings" Column | Type | Modifiers ----------+------+----------- a_string | text | not null Indexes: "strings_pkey" PRIMARY KEY, btree (a_string) test=# begin; alter table strings drop constraint strings_pkey; alter table strings add constraint new_pkey primary key (a_string); commit; BEGIN ALTER TABLE NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "new_pkey" for table "strings" ALTER TABLE COMMIT test=# \d strings; Table "public.strings" Column | Type | Modifiers ----------+------+----------- a_string | text | not null Indexes: "new_pkey" PRIMARY KEY, btree (a_string) Michael Glaesemann grzm seespotcode net ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend |