psql: Don't offer partitioned tables after CREATE INDEX CONCURRENTLY

From: Ishjaap Singh <ishjaap(dot)singh07(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: psql: Don't offer partitioned tables after CREATE INDEX CONCURRENTLY
Date: 2026-11-07 20:54:55
Message-ID: CA+Y2Bmfx9qpNKdKCTA8NOYetqbL1Y-22EToMc5tJcuNZz=Xf_Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

Tab completion after CREATE INDEX CONCURRENTLY [name] ON offers the
same relations as plain CREATE INDEX, including partitioned tables.
CREATE INDEX CONCURRENTLY isn't supported on partitioned tables, so
picking one always fails:

CREATE INDEX CONCURRENTLY ON parted (a);
ERROR: cannot create index on partitioned table "parted" concurrently

This happens on all supported branches.

The attached patch adds a relation list without partitioned tables and
uses it after CONCURRENTLY. Plain tables, materialized views and leaf
partitions are still offered, and plain CREATE INDEX is unchanged.

One detail in the rule change: in psql 18 and later, when a matching
completion rule finds nothing, psql moves on to the next matching one.
So with only the new list, "CREATE INDEX CONCURRENTLY ON <prefix of a
partitioned table>" still ended up in the plain CREATE INDEX rule,
which read CONCURRENTLY as the index name. The same happened with an
index actually named "index". The plain rule now needs CREATE or
UNIQUE right before INDEX and doesn't take CONCURRENTLY as the index
name, so a concurrent command can't reach it.

The new cases in 010_tab_completion.pl check that partitioned tables
are left out after CONCURRENTLY (with and without an index name, with
UNIQUE, and with an index named "index"), and that plain CREATE INDEX
still offers them. They fail without the fix. All psql TAP tests pass
on master and REL_19_STABLE, on Linux with GNU readline (I haven't
tried libedit), and pgindent is clean.

The patch is against master and also applies to REL_19_STABLE and
REL_18_STABLE. REL_15 to REL_17 only need the file name changed to
tab-complete.c. REL_14 needs two small changes (quote_ident() in the
query and the older two-argument macro). I have that version and have
tested it on REL_14_STABLE, and can post it if this should go back
that far.

This is the same kind of fix as the recent ones for DROP INDEX
CONCURRENTLY (f2edf5dd00d) and REFRESH MATERIALIZED VIEW CONCURRENTLY
(54f36adcbcd). There's also a long-running thread about allowing
CREATE INDEX CONCURRENTLY on partitioned tables [1]. If that goes in,
this completion would need to depend on the server version. I could not
find a posted fix for this.

[1] https://www.postgresql.org/message-id/6472861e485554974ff40375e6d4b81a@postgrespro.ru

Thanks,
Ishjaap Singh

Attachment Content-Type Size
v1-0001-psql-Don-t-offer-partitioned-tables-after-CREATE-.patch application/octet-stream 4.3 KB

Browse pgsql-hackers by date

  From Date Subject
Previous Message Jonathan S. Katz 2026-11-07 20:53:32 Re: PostgreSQL 19 GA press release draft