X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 656B011F60BD for ; Thu, 13 Apr 2006 00:44:39 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 required=5 tests=[none] Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id YFmhTz0zwlEq for ; Thu, 13 Apr 2006 00:44:36 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from hub.org (hub.org [200.46.204.220]) by postgresql.org (Postfix) with ESMTP id 0957611F60B9 for ; Thu, 13 Apr 2006 00:44:37 -0300 (ADT) Received: from localhost (unknown [200.46.204.254]) by hub.org (Postfix) with ESMTP id 1BABC62C871 for ; Thu, 13 Apr 2006 00:44:37 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org Received: from hub.org ([200.46.204.220]) by localhost (mx2.hub.org [200.46.204.254]) (amavisd-new, port 10024) with ESMTP id g7NFeheE48Zp for ; Thu, 13 Apr 2006 00:44:34 -0300 (ADT) Received: from ganymede.hub.org (blk-222-82-85.eastlink.ca [24.222.82.85]) by hub.org (Postfix) with ESMTP id 2EBBB62C86F for ; Thu, 13 Apr 2006 00:44:34 -0300 (ADT) Received: by ganymede.hub.org (Postfix, from userid 1000) id A299D3DB17; Thu, 13 Apr 2006 00:44:32 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by ganymede.hub.org (Postfix) with ESMTP id 9E96D3DAAF for ; Thu, 13 Apr 2006 00:44:32 -0300 (ADT) X-Return-Path: X-Received: from ganymede.hub.org ([unix socket]) by ganymede.hub.org (Cyrus v2.2.12) with LMTPA; Wed, 12 Apr 2006 23:40:34 -0300 X-Sieve: CMU Sieve 2.2 X-Received: from ganymede.hub.org (localhost [127.0.0.1]) by ganymede.hub.org (Postfix) with ESMTP id 6B2D43E07E for ; Wed, 12 Apr 2006 23:40:33 -0300 (ADT) X-Received: from mail.postgresql.org [200.46.204.71] by ganymede.hub.org with IMAP (fetchmail-6.3.2) for (single-drop); Wed, 12 Apr 2006 23:40:33 -0300 (ADT) X-Received: from postgresql.org ([unix socket]) by postgresql.org (Cyrus v2.2.12) with LMTPA; Wed, 12 Apr 2006 23:39:46 -0300 X-Sieve: CMU Sieve 2.2 X-Received: from localhost (mx2.hub.org [200.46.204.254]) by postgresql.org (Postfix) with ESMTP id D62F411F60AE for ; Wed, 12 Apr 2006 23:39:45 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Received: from postgresql.org ([200.46.204.71]) by localhost (mx2.hub.org [200.46.204.254]) (amavisd-new, port 10024) with ESMTP id TxgDd-b9ndVq for ; Wed, 12 Apr 2006 23:39:46 -0300 (ADT) X-Received: from postgresql.org (postgresql.org [200.46.204.71]) by postgresql.org (Postfix) with ESMTP id 2201011F66C2 for ; Wed, 12 Apr 2006 23:39:43 -0300 (ADT) X-Original-To: pgsql-sql-postgresql.org-owner@localhost.postgresql.org X-Delivered-To: pgsql-sql-postgresql.org-owner@localhost.postgresql.org X-Received: from localhost (mx2.hub.org [200.46.204.254]) by postgresql.org (Postfix) with ESMTP id A58F111F625B for ; Wed, 12 Apr 2006 23:39:42 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Received: from postgresql.org ([200.46.204.71]) by localhost (mx2.hub.org [200.46.204.254]) (amavisd-new, port 10024) with ESMTP id VsrQ1qc-4Sk7 for ; Wed, 12 Apr 2006 23:39:38 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- X-Received: from loki.globexplorer.com (loki.globexplorer.com [12.25.176.46]) by postgresql.org (Postfix) with ESMTP id 6E0F811F60A0 for ; Wed, 12 Apr 2006 23:39:31 -0300 (ADT) X-MimeOLE: Produced By Microsoft Exchange V6.0.6603.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Subject: Truncate and Foreign Key References question Date: Wed, 12 Apr 2006 19:43:00 -0700 Message-ID: <71E37EF6B7DCC1499CEA0316A2568328024BC2DF@loki.wc.globexplorer.net> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Truncate and Foreign Key References question Thread-Index: AcZeo/q0qAWhK0XORBKLSvTK9NNoyg== From: "Gregory S. Williamson" To: ReSent-Date: Thu, 13 Apr 2006 00:44:29 -0300 (ADT) ReSent-From: "Marc G. Fournier" ReSent-To: pgsql-sql@postgresql.org ReSent-Subject: Truncate and Foreign Key References question ReSent-Message-ID: <20060413004429.J1096@ganymede.hub.org> X-Archive-Number: 200604/103 X-Sequence-Number: 24912 This is in postgres 8.1: PostgreSQL 8.1.1 on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC) = 3.4.2 20041017 (Red Hat 3.4.2-6.fc3) I've got a table in one schema (work.client_collect_rates) which has an = FK constraint with a table, content.collections_l (definitions shown = below). There's about 500 entries currently in my collections_l table. I need to wipe out the contents of the collections_l table nightly and = refresh it from a remote master source. (Don't ask ... long & sordid = history) As the sequence below shows, I dropped the FK constraint successfully, = but when I run TRUNCATE collections_l it says: ERROR: cannot truncate a table referenced in a foreign key constraint DETAIL: Table "client_collect_rates" references "collections_l" via = foreign key constraint "$2". HINT: Truncate table "client_collect_rates" at the same time. This truncation of the second table is *not* an option, but since the = constraint "$2" is clearly gone, I am wondering what in the name of = sweet apples is going on ? Is this a bug ? Have a developed premature = senility ? Any clues for the clueless would be gratefully accepted! TIA, Greg Williamson DBA GlobeXplorer LLC billing=3D# \d work.client_collect_rates Table "work.client_collect_rates" Column | Type | Modifiers ---------------+---------+----------- contract_id | integer | not null collection_id | integer | not null rate | numeric | break_1 | numeric | rate_1 | numeric | break_2 | numeric | rate_2 | numeric | break_3 | numeric | rate_3 | numeric | break_4 | numeric | rate_4 | numeric | Indexes: "clnt_colrate_ndx" UNIQUE, btree (contract_id, collection_id) Foreign-key constraints: "$1" FOREIGN KEY (contract_id) REFERENCES = client_contracts(contract_id) "$2" FOREIGN KEY (collection_id) REFERENCES = content.collections_l(collect_id) billing=3D# \d content.collections_l Table "content.collections_l" Column | Type | Modifiers ----------------------+------------------------+-------------------- collect_id | integer | not null owner | integer | collection_name | character(50) | begin_date | date | end_date | date | pos_accuracy | integer | res_accuracy | integer | loc_code | character(30) | color | integer | default 0 category_id | integer | is_mosaic | integer | not null default 0 detail_metadata_view | character varying(255) | jdbc_url | character varying(255) | jdbc_driver | character varying(255) | Indexes: "collections_l_pkey" PRIMARY KEY, btree (collect_id) "collect_own_ndx" btree ("owner", collect_id) billing=3D# alter table work.client_collect_rates drop constraint "$2"; ALTER TABLE billing=3D# \d work.client_collect_rates Table "work.client_collect_rates" Column | Type | Modifiers ---------------+---------+----------- contract_id | integer | not null collection_id | integer | not null rate | numeric | break_1 | numeric | rate_1 | numeric | break_2 | numeric | rate_2 | numeric | break_3 | numeric | rate_3 | numeric | break_4 | numeric | rate_4 | numeric | Indexes: "clnt_colrate_ndx" UNIQUE, btree (contract_id, collection_id) Foreign-key constraints: "$1" FOREIGN KEY (contract_id) REFERENCES = client_contracts(contract_id) (Note that the "$2" FK is gone...) billing=3D# truncate content.collections_l; ERROR: cannot truncate a table referenced in a foreign key constraint DETAIL: Table "client_collect_rates" references "collections_l" via = foreign key constraint "$2". HINT: Truncate table "client_collect_rates" at the same time.