Re: TRUNCATE ONLY with foreign keys and triggers disabled

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dimitrios Apostolou <jimis(at)gmx(dot)net>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: TRUNCATE ONLY with foreign keys and triggers disabled
Date: 2025-04-14 14:45:01
Message-ID: 1257959.1744641901@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dimitrios Apostolou <jimis(at)gmx(dot)net> writes:
> While doing TRUNCATE ONLY I get:
> ERROR: cannot truncate a table referenced in a foreign key constraint
> But in my case the table to be truncated is already empty, and the
> TRIGGERS are disabled in all tables.

IIRC, it will let you do it if you truncate both the referenced and
referencing tables in the same command. The state of the triggers
is not material to this, since TRUNCATE doesn't fire them anyway.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dimitrios Apostolou 2025-04-14 14:53:20 Re: TRUNCATE ONLY with foreign keys and triggers disabled
Previous Message Tom Lane 2025-04-14 14:36:40 Re: ICU Collations and Collation Updates