public inbox for [email protected]
help / color / mirror / Atom feedFrom: Dimitrios Apostolou <[email protected]>
To: Tom Lane <[email protected]>
Cc: [email protected]
Subject: Re: TRUNCATE ONLY with foreign keys and triggers disabled
Date: Mon, 14 Apr 2025 16:53:20 +0200 (CEST)
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
<[email protected]>
On Mon, 14 Apr 2025, Tom Lane wrote:
> Dimitrios Apostolou <[email protected]> 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.
Thanks Tom, however that is not possible in my case, the referenced table
is possibly just populated and potentially very big (partitioned table
with many sub-partitions).
Context is that I've modified pg_restore to accept --data-only --clean,
and issues a TRUNCATE ONLY before each table's COPY, in the same
transaction (thus avoiding WAL too). Will send an RFC patch to
pgsql-hackers when I verify it works.
Dimitris
view thread (4+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: TRUNCATE ONLY with foreign keys and triggers disabled
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox