Re: Sometimes referential integrity seems not to work

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
Cc: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Enio Schutt Junior <enio(at)pmpf(dot)rs(dot)gov(dot)br>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Sometimes referential integrity seems not to work
Date: 2004-02-03 13:32:28
Message-ID: 401FA2EC.2090308@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

scott.marlowe wrote:

> On Mon, 2 Feb 2004, Jan Wieck wrote:
>
>> Stephan Szabo wrote:
>>
>> > On Sat, 31 Jan 2004, Tom Lane wrote:
>> >
>> >> Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)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.

Okay, so you're the third one correcting me on this. Now can any of you
violate a foreign key constraint with anything else than using truncate
in a pre-7.3 database? Because I can't do that and that was the original
problem.

Jan

>
> => select * from test2;
> info
> -------------
> abc'123
> 123
> (2 rows)
>
> => begin;
> BEGIN
> => truncate test2;
> TRUNCATE TABLE
> => rollback;
> ROLLBACK
> => select * from test2;
> info
> -------------
> abc'123
> 123
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Christoph Haller 2004-02-03 15:08:05 Re: locking problem
Previous Message arun raj 2004-02-03 13:06:35 request to plsql tutorial