Re: Sometimes referential integrity seems not to work - Mailing list pgsql-sql

From scott.marlowe
Subject Re: Sometimes referential integrity seems not to work
Date
Msg-id Pine.LNX.4.33.0402021138340.19673-100000@css120.ihs.com
Whole thread Raw
In response to Re: Sometimes referential integrity seems not to work  (Jan Wieck <JanWieck@Yahoo.com>)
Responses Re: Sometimes referential integrity seems not to work  (Jan Wieck <JanWieck@Yahoo.com>)
List pgsql-sql
On Mon, 2 Feb 2004, Jan Wieck wrote:

> Stephan Szabo wrote:
> 
> > On Sat, 31 Jan 2004, Tom Lane wrote:
> > 
> >> Stephan Szabo <sszabo@megazone.bigpanda.com> 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




pgsql-sql by date:

Previous
From: Rod Taylor
Date:
Subject: Re: Sometimes referential integrity seems not to work
Next
From: Terry Lee Tucker
Date:
Subject: Novice SQL Question