[PATCH] psql: Add tab completion for INSERT ... ON CONFLICT

From: Abed Alawieh <abedalaweye(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: [PATCH] psql: Add tab completion for INSERT ... ON CONFLICT
Date: 2026-12-06 00:05:44
Message-ID: CAAr_ne7o9bsaNJUs2eEwFS_mGwKKQUuQuV=fB0GuA3JvCqgrfQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

psql currently offers no tab completion after ON CONFLICT, and
"... ON CONFLICT (c1) DO UPDATE <TAB>" falls through to the generic
UPDATE rule and offers table names.

The attached patch completes:

- ON CONFLICT -> "(", ON CONSTRAINT, DO
- the conflict target -> WHERE (index predicate) or DO
- ON CONFLICT DO -> NOTHING only, because DO UPDATE and DO SELECT need
a conflict target and are rejected at parse analysis without one
- ON CONFLICT <target> DO -> NOTHING, SELECT, UPDATE SET
- DO NOTHING -> RETURNING
- DO SELECT (commit 88327092) -> FOR, RETURNING, WHERE; the lock
strengths after FOR; and RETURNING/WHERE after the lock strength

It also stops "DO UPDATE SET <TAB>" (and MERGE's "THEN UPDATE SET
<TAB>") from offering configuration parameters.

The DO UPDATE / DO SELECT rules are skipped inside CREATE [OR REPLACE]
RULE, where DO is followed by the rule action, which can itself be an
UPDATE or SELECT.

Things I left out on purpose and could add in a follow-up if people want
them: completing constraint names after ON CONSTRAINT (it would need a
query restricted to unique/primary key/exclusion constraints and a way to
find the target table), and column names inside the conflict target and
after DO UPDATE SET.

TAP tests are added to src/bin/psql/t/010_tab_completion.pl. Builds
without warnings, pgindent is clean, and the psql test suite passes.

I'll add it to the next CommitFest.

Regards,
Abed Alawieh

Attachment Content-Type Size
v1-0001-psql-Add-tab-completion-for-INSERT-.-ON-CONFLICT.patch application/octet-stream 5.6 KB

Browse pgsql-hackers by date

  From Date Subject
Previous Message Tomas Vondra 2026-12-05 23:45:23 Re: Making type Datum be 8 bytes everywhere