Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id D2E69632CB9 for ; Thu, 14 Jan 2010 23:34:29 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 39897-01 for ; Fri, 15 Jan 2010 03:34:18 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pz0-f201.google.com (mail-pz0-f201.google.com [209.85.222.201]) by mail.postgresql.org (Postfix) with ESMTP id 29C756325F4 for ; Thu, 14 Jan 2010 23:34:18 -0400 (AST) Received: by pzk39 with SMTP id 39so306223pzk.15 for ; Thu, 14 Jan 2010 19:34:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=NkMF6gumaF4fQcTL8Rv2yfFSFQGewvf2CyUXuOdC8Bo=; b=kuUK391KO/czvNYH8wgeTzzXDYRrwQ88i49xklS3QAmxnNidUkiTCF0RF1LDQmvm8D lVzkNxaBBbUV093JRsNxcffCbZHBH4pBKtOQzTFrPlQ27Googk3IajLR5ZZOB75YqgIY g2AipkmK35FQs1BFX58K2T2Mmp+gZj2F4qpzY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=aUBYHgaTSrbURGjNhj3kthGI+WZi0XJVCKA8oEa57QMlsOnc3D/ebDb/D0C2nlwjQs a/YnmugVQoGNbqLxPt8MV+AgWn7Aj/Z0Yr9yYXOgFsyMPUXi4Gi5Z7ng10J1tTKi0xL/ +RzzdkybhkYPoY0EsKP3oAud2w+mQM/XBN1I8= MIME-Version: 1.0 Received: by 10.115.27.18 with SMTP id e18mr1187328waj.133.1263526455603; Thu, 14 Jan 2010 19:34:15 -0800 (PST) In-Reply-To: <87hbqo11yg.fsf@kolob.sebmags.homelinux.org> References: <87hbqo11yg.fsf@kolob.sebmags.homelinux.org> Date: Fri, 15 Jan 2010 12:34:15 +0900 Message-ID: <1d581afe1001141934x2c525992w2e4bcf40a3113207@mail.gmail.com> Subject: Re: rename primary key From: Ian Barwick To: Seb Cc: pgsql-sql@postgresql.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.589 tagged_above=-10 required=5 tests=BAYES_00=-2.599, FH_DATE_PAST_20XX=3.188 X-Spam-Level: X-Archive-Number: 201001/26 X-Sequence-Number: 33562 2010/1/15 Seb : > Hi, > > Is it possible to rename a primary key? =C2=A0I learnt that to rename for= eign > keys one has to drop it and recreate with the new name, or add a new new > and drop the old one. =C2=A0What is the approach for primary keys? =C2=A0= Thanks. Is this what you mean? psql (8.4.2) You are now connected to database "test". test=3D# CREATE TABLE foo (id serial primary key); NOTICE: CREATE TABLE will create implicit sequence "foo_id_seq" for serial column "foo.id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "foo_pkey" for table "foo" CREATE TABLE test=3D# \d foo Table "public.foo" Column | Type | Modifiers --------+---------+-------------------------------------------------- id | integer | not null default nextval('foo_id_seq'::regclass) Indexes: "foo_pkey" PRIMARY KEY, btree (id) test=3D# ALTER INDEX foo_pkey RENAME to bar_fkey; ALTER INDEX test=3D# \d foo Table "public.foo" Column | Type | Modifiers --------+---------+-------------------------------------------------- id | integer | not null default nextval('foo_id_seq'::regclass) Indexes: "bar_fkey" PRIMARY KEY, btree (id) test=3D# Ian Barwick