public inbox for [email protected]
help / color / mirror / Atom feedFrom: vignesh C <[email protected]>
To: PostgreSQL Hackers <[email protected]>
Subject: Fix tab completion after EXCEPT (...) in IMPORT FOREIGN SCHEMA
Date: Wed, 15 Apr 2026 18:42:47 +0530
Message-ID: <CALDaNm1-Fx6Msw6zcRuSjgQdw6asdTyp2DwP-4TCKGYAT+ndsA@mail.gmail.com> (raw)
Hi all,
While reviewing tab completion behavior, I noticed an issue after
EXCEPT (...) support was added to CREATE PUBLICATION.
Currently, after typing:
IMPORT FOREIGN SCHEMA public EXCEPT (t1)
psql correctly suggests FROM SERVER. However, the existing completion
rule uses a generic:
TailMatches("EXCEPT", "(*)")
Previously this was safe because no other command used EXCEPT (...).
Now that CREATE PUBLICATION also supports EXCEPT (...), the same rule
can incorrectly match publication commands and suggest FROM SERVER
there as well.
The attached patch fixes this by restricting the EXCEPT (...) path to
IMPORT FOREIGN SCHEMA using HeadMatches(), while preserving the
existing LIMIT TO (...) behavior.
Regards,
Vignesh
Attachments:
[application/octet-stream] 0001-Fix-tab-completion-after-EXCEPT-in-IMPORT-FOREIGN-SC.patch (1.8K, 2-0001-Fix-tab-completion-after-EXCEPT-in-IMPORT-FOREIGN-SC.patch)
download | inline diff:
From 0558aeaad6b018804aacf60ef00bb4dc3ad62e7e Mon Sep 17 00:00:00 2001
From: Vignesh C <[email protected]>
Date: Wed, 15 Apr 2026 18:30:03 +0530
Subject: [PATCH] Fix tab completion after EXCEPT() in IMPORT FOREIGN SCHEMA
Tab completion for IMPORT FOREIGN SCHEMA incorrectly suggested FROM
SERVER after EXCEPT (...), because EXCEPT (...) is now also valid in
CREATE and ALTER PUBLICATION.
Previously, the generic TailMatches("EXCEPT", "(*)") check was safe
because no other command used 'EXCEPT (...)'. After adding support for
'EXCEPT (...)' in publication commands, the same completion rule started
matching unrelated statements and incorrectly offered 'FROM SERVER'
there as well.
Fix this by restricting the 'EXCEPT (...)' completion path to
'IMPORT FOREIGN SCHEMA' using HeadMatches(), while keeping the
existing 'LIMIT TO (...)' behavior unchanged.
This ensures 'FROM SERVER' is suggested only for valid
'IMPORT FOREIGN SCHEMA' syntax.
---
src/bin/psql/tab-complete.in.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index 9990f818942..88444096dc1 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -4899,9 +4899,11 @@ match_previous_words(int pattern_id,
COMPLETE_WITH("SCHEMA");
else if (Matches("IMPORT", "FOREIGN", "SCHEMA", MatchAny))
COMPLETE_WITH("EXCEPT (", "FROM SERVER", "LIMIT TO (");
- else if (TailMatches("LIMIT", "TO", "(*)") ||
+ else if (HeadMatches("IMPORT", "FOREIGN", "SCHEMA", MatchAny) &&
TailMatches("EXCEPT", "(*)"))
COMPLETE_WITH("FROM SERVER");
+ else if (TailMatches("LIMIT", "TO", "(*)"))
+ COMPLETE_WITH("FROM SERVER");
else if (TailMatches("FROM", "SERVER", MatchAny))
COMPLETE_WITH("INTO");
else if (TailMatches("FROM", "SERVER", MatchAny, "INTO"))
--
2.43.0
view thread (6+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: Fix tab completion after EXCEPT (...) in IMPORT FOREIGN SCHEMA
In-Reply-To: <CALDaNm1-Fx6Msw6zcRuSjgQdw6asdTyp2DwP-4TCKGYAT+ndsA@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox