Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 0E88CB620A7 for ; Thu, 2 Jun 2011 12:04:47 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 92310-09-2 for ; Thu, 2 Jun 2011 15:04:39 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from spinlock.commandprompt.com (host-215.commandprompt.net [207.173.203.215]) by mail.postgresql.org (Postfix) with ESMTP id 41687B61FA8 for ; Thu, 2 Jun 2011 12:04:36 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by spinlock.commandprompt.com (Postfix) with ESMTP id B2893348045; Thu, 2 Jun 2011 08:04:35 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at commandprompt.com Received: from spinlock.commandprompt.com ([127.0.0.1]) by localhost (spinlock.commandprompt.com.commandprompt.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OHOr+fM7eJMl; Thu, 2 Jun 2011 08:04:33 -0700 (PDT) Received: from [172.16.132.70] (unknown [88.135.121.46]) by spinlock.commandprompt.com (Postfix) with ESMTPSA id CC1CA348044; Thu, 2 Jun 2011 08:04:32 -0700 (PDT) Subject: Re: BUG #6048: TRUNCATE vs TRUNCATE CASCADE: misleading message Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Alexey Klyukin In-Reply-To: <201106021123.p52BNgZL053022@wwwmaster.postgresql.org> Date: Thu, 2 Jun 2011 18:04:29 +0300 Cc: pgsql-bugs@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <4D7D2D17-FD02-44D7-BE00-340369E816DB@commandprompt.com> References: <201106021123.p52BNgZL053022@wwwmaster.postgresql.org> To: Artiom Makarov X-Mailer: Apple Mail (2.1084) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201106/17 X-Sequence-Number: 30396 On Jun 2, 2011, at 2:23 PM, Artiom Makarov wrote: >=20 > The following bug has been logged online: >=20 > Bug reference: 6048 > Logged by: Artiom Makarov > Email address: artiom.makarov@gmail.com > PostgreSQL version: 9.04 > Operating system: 2.6.32-30-server #59-Ubuntu SMP Tue Mar 1 22:46:09 = UTC > 2011 x86_64 GNU/Linux > Description: TRUNCATE vs TRUNCATE CASCADE: misleading message > Details:=20 >=20 > create table tr_test1(id1 int, primary key(id1)); > create table tr_test2(id2 int, id int, primary key(id2), foreign key = (id) > references tr_test1(id1) MATCH SIMPLE ON UPDATE RESTRICT ON DELETE > RESTRICT); > create table tr_test3(id3 int, id int, primary key(id3), foreign key = (id) > references tr_test2(id2) MATCH SIMPLE ON UPDATE RESTRICT ON DELETE > RESTRICT); >=20 > insert into tr_test1(id1) values (1); > insert into tr_test2(id2,id) values (1,1); > insert into tr_test2(id2,id) values (2,1); > insert into tr_test3(id3,id) values (1,2); >=20 > truncate tr_test1; >=20 > ERROR: cannot truncate a table referenced in a foreign key constraint > SQL state: 0A000 > Detail: Table "tr_test2" references "tr_test1". > Hint: Truncate table "tr_test2" at the same time, or use TRUNCATE ... > CASCADE. >=20 > This is definetly misleading message, because of when applying = truncate > tr_test1 CASCADE; all 3 tables truncated: What would you expect to happen for TRUNCATE .. CASCADE?=20 One thing I find potentially surprising is that TRUNCATE CASCADE doesn't = follow the semantics of 'ON DELETE' clause for the foreign key, i.e. it = would truncate the dependent table even with ON DELETE RESTRICT foreign = key. Do we need a similar 'ON TRUNCATE' FK clause? >=20 > NOTICE: truncate cascades to table "tr_test2" > NOTICE: truncate cascades to table "tr_test3" >=20 >=20 > While drop schema public; command list all affected objects: >=20 > ERROR: cannot drop schema public because other objects depend on it >=20 > SQL state: 2BP01 > Detail: table tr_test1 depends on schema public > table tr_test2 depends on schema public > table tr_test3 depends on schema public > Hint: Use DROP ... CASCADE to drop the dependent objects too. -- Alexey Klyukin The PostgreSQL Company - Command Prompt, Inc.