[PATCH] Fix psql tab completion for REPACK boolean options

First seen: 2026-05-11 19:45:34+00:00 · Messages: 9 · Participants: 4

Latest Update

2026-05-20 · claude-opus-4-6

Incremental Update: Proposal for Centralized DefElem Option Handling

A new participant (Thom) raises an architectural question about the root cause of the duplicate-option bug: the lack of shared infrastructure for parsing DefElem option lists across commands.

The Proposal

Thom observes that REPACK, VACUUM, and EXPLAIN all independently implement the same boilerplate pattern for processing parenthesized option lists:

  1. Iterate over a DefElem list
  2. Reject unknown option names
  3. Coerce values via defGetBoolean() (or similar)
  4. Apply last-duplicate-wins semantics for repeated options

Each command currently writes its own version of this loop, which is how the REPACK bug (OR-accumulate instead of overwrite) slipped in. Thom proposes a common utility routine that accepts:

The routine would handle iteration, unknown-option rejection, type coercion, and last-wins semantics generically. Command-specific semantic validation (e.g., conflicting option combinations) would remain in command code.

Response from Álvaro Herrera

Álvaro's response is brief and neutral — he notes the options differ per command but invites a patch if Thom sees room for improvement. No objection to the concept, but no endorsement either.

Assessment

This is a reasonable refactoring idea that addresses the structural cause of the class of bugs discovered in this thread. However, Thom self-defers it ("probably something for later" given the dev cycle timing), so no patch is forthcoming immediately. The idea is architecturally sound but represents future work, not active development.

History (1 prior analysis)
2026-05-18 · claude-opus-4-6

Incremental Update: REPACK Option Parsing Bugs Discovered and Fixed

The original tab-completion patch has been committed. More significantly, Fujii discovered two additional server-side parsing bugs in the REPACK command's option handling while testing the tab-completion fix. These are real behavioral bugs, not just UX/completion issues.

New Bug #1: CONCURRENTLY OFF Fails

REPACK (CONCURRENTLY OFF) raises:

ERROR: unrecognized REPACK option "concurrently"

while REPACK (CONCURRENTLY ON) works correctly. This indicates the option-parsing code only recognizes the CONCURRENTLY keyword when the value is ON — a clear asymmetry bug in the option dispatch logic.

New Bug #2: Duplicate Option Last-Value-Wins Semantics Broken

When the same boolean option is specified multiple times (e.g., REPACK (VERBOSE ON, VERBOSE OFF)), the implementation fails to honor last-value-wins semantics. Specifically, if any occurrence sets an option to ON, it stays ON regardless of subsequent OFF settings. This suggests the parsing uses an OR/accumulate pattern rather than a proper overwrite pattern for duplicate keys.

Resolution

Both bugs were fixed in a follow-up patch authored by Fujii, reviewed (cursory, not tested) by Álvaro Herrera, and subsequently pushed by Fujii on 2026-05-18.

Significance

These are server-side correctness bugs (not just tab-completion cosmetics), meaning they affect actual command execution. The discovery pathway — finding real parsing bugs while testing a tab-completion fix — is a nice example of how UX-level testing can surface deeper issues.