Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id E172AB62688 for ; Thu, 2 Jun 2011 14:50:14 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 44111-06-5 for ; Thu, 2 Jun 2011 17:50:08 +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 D0826B6262D for ; Thu, 2 Jun 2011 14:50:05 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by spinlock.commandprompt.com (Postfix) with ESMTP id 31C5C348046; Thu, 2 Jun 2011 10:50:05 -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 lKxhG4I6rK8G; Thu, 2 Jun 2011 10:50:03 -0700 (PDT) Received: from [172.16.132.70] (unknown [88.135.121.46]) by spinlock.commandprompt.com (Postfix) with ESMTPSA id 431B0348045; Thu, 2 Jun 2011 10:50:02 -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: Date: Thu, 2 Jun 2011 20:49:59 +0300 Cc: pgsql-bugs@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <8E5AE8FB-F364-4155-9BDC-0E218BE6BF2A@commandprompt.com> References: <201106021123.p52BNgZL053022@wwwmaster.postgresql.org> <4D7D2D17-FD02-44D7-BE00-340369E816DB@commandprompt.com> 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/20 X-Sequence-Number: 30399 On Jun 2, 2011, at 6:21 PM, Artiom Makarov wrote: > 2011/6/2 Alexey Klyukin : >=20 >> 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 >=20 > Yes, cascade truncating taked place without ON DELETE RESTRICT > checking. No matter. > Either TRUNCATE must show message with full objects tree - correct > behavior like DROP, or TRUNCATE CASCADE should not delete anything > (strict constraint checking). Well, in your example it actually shows all the direct dependencies: > 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); tr_test3 here depends on tr_test2, and not directly on tr_test1. Still, even if tr_test3.id would reference tr_test.id in your example, = only the first dependency is shown (for truncate, delete and probably update): Table "public.test" Column | Type | Modifiers=20 --------+---------+----------- id | integer | not null name | text |=20 Indexes: "test_pkey" PRIMARY KEY, btree (id) Referenced by: TABLE "test2" CONSTRAINT "test2_id_fkey" FOREIGN KEY (id) REFERENCES = test(id) ON DELETE RESTRICT TABLE "test3" CONSTRAINT "test3_id_fkey" FOREIGN KEY (id) REFERENCES = test(id) ON DELETE RESTRICT postgres=3D# delete from test; ERROR: update or delete on table "test" violates foreign key constraint = "test2_id_fkey" on table "test2" DETAIL: Key (id)=3D(1) is still referenced from table "test2". I wonder whether this behavior is intentional, to avoid bloat in the = logs. To view all the dependencies you can just do \d tablename after receiving = the error. -- Alexey Klyukin The PostgreSQL Company - Command Prompt, Inc.