X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 8DBB3D1D286 for ; Mon, 2 Feb 2004 18:47:06 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 34911-02 for ; Mon, 2 Feb 2004 14:46:59 -0400 (AST) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by svr1.postgresql.org (Postfix) with ESMTP id 359BAD1D2AC for ; Mon, 2 Feb 2004 14:46:58 -0400 (AST) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.10/8.12.10) with ESMTP id i12IhoRC010916; Mon, 2 Feb 2004 11:43:50 -0700 (MST) Date: Mon, 2 Feb 2004 11:40:01 -0700 (MST) From: "scott.marlowe" To: Jan Wieck Cc: Stephan Szabo , Tom Lane , Enio Schutt Junior , Subject: Re: Sometimes referential integrity seems not to work In-Reply-To: <401E80D2.9080909@Yahoo.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-IHS-MailScanner: Found to be clean X-IHS-MailScanner-SpamCheck: X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/22 X-Sequence-Number: 16713 On Mon, 2 Feb 2004, Jan Wieck wrote: > Stephan Szabo wrote: > > > On Sat, 31 Jan 2004, Tom Lane wrote: > > > >> Stephan Szabo writes: > >> > On Mon, 26 Jan 2004, Enio Schutt Junior wrote: > >> >> In a database I am working, I sometimes have to delete all the records in > >> >> some tables. According to the referential integrity defined in the creation > >> >> of the tables, postmaster should not delete the records, but it does. I have > >> >> used the following commands: "delete from table_1" and "truncate table_1". > >> >> ... > >> >> can the postgres user delete records despite referential integrity? > >> > >> I think the first PG release or two that had TRUNCATE TABLE would allow > >> you to apply it despite the existence of foreign-key constraints on the > >> table. Recent releases won't though. > > > > Yeah, truncate didn't worry me much, but the implication that delete from > > table_1; worked did. > > TRUNCATE cannot be used inside of a transaction, and since 7.3 it checks > for foreign keys. So I guess Enio is getting but ignoring the error > message when trying the delete, but then the truncate does the job in > his pre-7.3 database. Yes it can. I think it was starting in 7.3. => select * from test2; info ------------- abc'123 123 (2 rows) => begin; BEGIN => truncate test2; TRUNCATE TABLE => rollback; ROLLBACK => select * from test2; info ------------- abc'123 123