BUG #19858: pg_dump --clean --if-exists fails on NOT VALID domain constraint

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: 125atishprak(at)gmail(dot)com
Subject: BUG #19858: pg_dump --clean --if-exists fails on NOT VALID domain constraint
Date: 2026-11-09 13:22:08
Message-ID: 19858-5a734f08714a5c73@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19858
Logged by: Atish Prakash
Email address: 125atishprak(at)gmail(dot)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.

Browse pgsql-bugs by date

  From Date Subject
Next Message Bertrand Drouvot 2026-11-09 14:47:17 Re: BUG #19839: Assert in ReorderBufferRestoreCleanup for aborted, spilled transaction
Previous Message Jesper St John 2026-11-09 13:19:29 Re: Timing issue in pg_basebackup