On 2026-Nov-05, Michael Paquier wrote:

> On Wed, Nov 04, 2026 at 11:54:26PM -0500, shihao zhong wrote:

> > This is a little trick because it did change the behavior, I dont think user
> > want to create an incorrect PK and running FINALIZE first is easy,
> > so I think this is fine to backport.
> 
> +   if (PartitionHasPendingDetach(pd->oids[i]))
> +       ereport(ERROR,
> +               (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
> +                errmsg("cannot create index on partitioned table \"%s\"",
> +                       RelationGetRelationName(rel)),
> +                errdetail("Partition \"%s\" has an incomplete detach.",
> +                          get_rel_name(pd->oids[i])),
> +                errhint("Use ALTER TABLE ... DETACH PARTITION ... FINALIZE 
> to complete the pending detach operation.")));
> 
> Still returning an error may be better than breaking a tree
> consistency and even worse, break constraints under-the-hood.  I am
> not sure if there is a better option here..  Alvaro, what do you
> think?

I think this idea is good generally speaking, but we shouldn't limit it
to create index, but instead apply it to pretty much any DDL that you
want to run on such a table.  The risk of inconsistencies is just too
high and there's no functional reason to let users do anything before
finishing that detach.

I'm happy to listen to example scenarios where my argument fails, to
assess if any exceptions are needed.

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/
"Por suerte hoy explotó el califont porque si no me habría muerto
 de aburrido"  (Papelucho)


Reply via email to