TRUNCATE ONLY with foreign keys and triggers disabled

From: Dimitrios Apostolou <jimis(at)gmx(dot)net>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: TRUNCATE ONLY with foreign keys and triggers disabled
Date: 2025-04-14 10:57:04
Message-ID: edf978ea-6cf8-b2c1-4866-3fa7ae160836@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello list,

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.

I wonder, is there a deeper reason for this error, or is it just an
implementation shortcoming? In other words, how easy would it be to write
a patch that allows TRUNCATE even with foreign keys when triggers are
disabled or the table is empty?

Thanks in advance,
Dimitris

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Laurenz Albe 2025-04-14 11:05:01 Re: ICU Collations and Collation Updates
Previous Message Wolfgang Walther 2025-04-14 10:18:44 Re: Interesting case of IMMUTABLE significantly hurting performance