From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: 125atishprak@gmail.com
Subject: BUG #19858: pg_dump --clean --if-exists fails on NOT VALID domain constraint
Date: Mon, 09 Nov 2026 13:22:08 +0000
Message-ID: <19858-5a734f08714a5c73@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 19858
Logged by: Atish Prakash
Email address: 125atishprak@gmail.com
PostgreSQL version: 18.6
Operating system: Linux x86_64
Description:
The pg_dump documentation says --if-exists suppresses "does not exist"
errors
when restoring with --clean. A separately dumped domain constraint is not
covered,
because the command it generates has no guard on the domain itself.
CREATE DOMAIN d AS int;
ALTER DOMAIN d ADD CONSTRAINT k CHECK (VALUE > 0) NOT VALID;
pg_dump --clean --if-exists mydb > dump.sql
The dump starts with:
ALTER DOMAIN public.d DROP CONSTRAINT IF EXISTS k;
DROP DOMAIN IF EXISTS public.d;
Restoring into an empty database gives:
ERROR: type "public.d" does not exist
With psql -v ON_ERROR_STOP=1 the restore stops at that point, before
creating
anything. Other objects in the same test, using ALTER TABLE IF EXISTS and
DROP ...
IF EXISTS, gave no such error.
Expected: no "does not exist" error with --if-exists.
ALTER DOMAIN has no IF EXISTS form for the domain, so the fix could be to
add one,
or to skip the constraint drop since DROP DOMAIN follows it. I have not
written a
patch.
Found with dump and restore differential tests. I reproduced and checked the
result myself.
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, 125atishprak@gmail.com
Subject: Re: BUG #19858: pg_dump --clean --if-exists fails on NOT VALID domain constraint
In-Reply-To: <19858-5a734f08714a5c73@postgresql.org>
References: <19858-5a734f08714a5c73@postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox