Subject: TRUNCATE ONLY with foreign keys and triggers disabled

From: Dimitrios Apostolou <[email-masked]>
Date: Mon, 14 Apr 2025 12:57:04 +0200 (CEST)

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

---

From: Tom Lane <[email-masked]>
Date: Mon, 14 Apr 2025 10:45:01 -0400

> 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