Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 66C3F18E38D9 for ; Thu, 12 Jan 2012 12:55:02 -0400 (AST) Received: from mail-gx0-f174.google.com ([209.85.161.174]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RlNvY-0001qF-1O for pgsql-sql@postgresql.org; Thu, 12 Jan 2012 16:55:01 +0000 Received: by ggdk6 with SMTP id k6so1089715ggd.19 for ; Thu, 12 Jan 2012 08:54:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:cc:references:in-reply-to :mime-version:content-type:content-transfer-encoding:message-id; bh=ULkeE3A1bQ+7Ma0yUyhIhv6YNjm2BRNlAOouzTh6YJs=; b=F22ITn8oPEagbbFSP7TyVK39i08RcSxoDcakCe2fnJ/Y2hbnsRgKxMkJedwb9gf4z3 QXUBUXAF7DkKbSHwlIKAvVdwdRGuUphlyBYfA2JQvBPf0zErhK7TTiVyP587u0RbXr2Y iUwDCwv1Dsgqa9Hdo/k3wjS/os1BM8vJ9Ac1o= Received: by 10.50.191.200 with SMTP id ha8mr4796652igc.27.1326387286839; Thu, 12 Jan 2012 08:54:46 -0800 (PST) Received: from tucker.localnet (c-24-17-164-54.hsd1.wa.comcast.net. [24.17.164.54]) by mx.google.com with ESMTPS id 36sm19083265ibc.6.2012.01.12.08.54.44 (version=SSLv3 cipher=OTHER); Thu, 12 Jan 2012 08:54:45 -0800 (PST) From: Adrian Klaver To: pgsql-sql@postgresql.org Subject: Re: Unable To Modify Table Date: Thu, 12 Jan 2012 08:54:41 -0800 User-Agent: KMail/1.13.5 (Linux/2.6.32-37-generic; KDE/4.4.5; i686; ; ) Cc: Carlos Mennens References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201201120854.42306.adrian.klaver@gmail.com> X-Pg-Spam-Score: -2.7 (--) X-Archive-Number: 201201/48 X-Sequence-Number: 36219 On Thursday, January 12, 2012 8:42:59 am Carlos Mennens wrote: > I seem to have an issue where I can't modify a table due to another > tables foreign key association: > > [CODE]trinity=# \d developers > Table "public.developers" > Column | Type | Modifiers > --------------+----------------+----------- > id | character(10) | not null > name | character(50) | not null > address | character(50) | > city | character(50) | > state | character(2) | > zip | character(10) | > country | character(50) | > phone | character(50) | > email | character(255) | > Indexes: > "developers_pkey" PRIMARY KEY, btree (id) > Referenced by: > TABLE "orders" CONSTRAINT "fk_orders_developers" FOREIGN KEY (id) > REFERENCES developers(id) > [/CODE] > > > Now when I try and change the values before I alter the field TYPE, I > get an error that another table (orders) with a foreign key associated > with public.developers 'id' field still has old values therefor can't > change / modify the 'developers' table. > > [CODE]trinity=# UPDATE developers SET id = '1000' WHERE id = '1000000001'; > ERROR: update or delete on table "developers" violates foreign key > constraint "fk_orders_developers" on table "orders" > DETAIL: Key (id)=(1000000001) is still referenced from table "orders". > [/CODE] > > How does one accomplish my goal? Is this difficult to change or once > that foreign key is created, are you stuck with that particular > constraint? You are pushing in the wrong direction. You need to make the change in the table 'orders'. This assumes the FK in 'orders' has ON UPDATE CASCADE enabled. -- Adrian Klaver adrian.klaver@gmail.com