public inbox for [email protected]
help / color / mirror / Atom feedFix tab completion after EXCEPT (...) in IMPORT FOREIGN SCHEMA
6+ messages / 3 participants
[nested] [flat]
* Fix tab completion after EXCEPT (...) in IMPORT FOREIGN SCHEMA
@ 2026-04-15 13:12 vignesh C <[email protected]>
0 siblings, 1 reply; 6+ messages in thread
From: vignesh C @ 2026-04-15 13:12 UTC (permalink / raw)
To: PostgreSQL Hackers <[email protected]>
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
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Fix tab completion after EXCEPT (...) in IMPORT FOREIGN SCHEMA
@ 2026-04-16 03:59 shveta malik <[email protected]>
parent: vignesh C <[email protected]>
0 siblings, 1 reply; 6+ messages in thread
From: shveta malik @ 2026-04-16 03:59 UTC (permalink / raw)
To: vignesh C <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>; shveta malik <[email protected]>
On Wed, Apr 15, 2026 at 8:45 PM vignesh C <[email protected]> wrote:
>
> 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.
>
I can reproduce the problem without the patch. The patch looks good to me.
thanks
Shveta
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Fix tab completion after EXCEPT (...) in IMPORT FOREIGN SCHEMA
@ 2026-04-16 17:09 Fujii Masao <[email protected]>
parent: shveta malik <[email protected]>
0 siblings, 1 reply; 6+ messages in thread
From: Fujii Masao @ 2026-04-16 17:09 UTC (permalink / raw)
To: shveta malik <[email protected]>; +Cc: vignesh C <[email protected]>; PostgreSQL Hackers <[email protected]>
On Thu, Apr 16, 2026 at 1:00 PM shveta malik <[email protected]> wrote:
>
> On Wed, Apr 15, 2026 at 8:45 PM vignesh C <[email protected]> wrote:
> >
> > 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.
Thanks for the patch!
- 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");
Do we really need to split this into two conditions? Wouldn't it be simpler
to keep a single condition?, for example:
-------------------
else if (TailMatches("LIMIT", "TO", "(*)") ||
- TailMatches("EXCEPT", "(*)"))
+ Matches("IMPORT", "FOREIGN", "SCHEMA", MatchAny, "EXCEPT", "(*)"))
COMPLETE_WITH("FROM SERVER");
-------------------
Regards,
--
Fujii Masao
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Fix tab completion after EXCEPT (...) in IMPORT FOREIGN SCHEMA
@ 2026-04-17 04:32 vignesh C <[email protected]>
parent: Fujii Masao <[email protected]>
0 siblings, 1 reply; 6+ messages in thread
From: vignesh C @ 2026-04-17 04:32 UTC (permalink / raw)
To: Fujii Masao <[email protected]>; +Cc: shveta malik <[email protected]>; PostgreSQL Hackers <[email protected]>
On Thu, 16 Apr 2026 at 22:39, Fujii Masao <[email protected]> wrote:
>
> On Thu, Apr 16, 2026 at 1:00 PM shveta malik <[email protected]> wrote:
> >
> > On Wed, Apr 15, 2026 at 8:45 PM vignesh C <[email protected]> wrote:
> > >
> > > 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.
>
> Thanks for the patch!
>
> - 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");
>
> Do we really need to split this into two conditions? Wouldn't it be simpler
> to keep a single condition?, for example:
>
> -------------------
> else if (TailMatches("LIMIT", "TO", "(*)") ||
> - TailMatches("EXCEPT", "(*)"))
> + Matches("IMPORT", "FOREIGN", "SCHEMA", MatchAny, "EXCEPT", "(*)"))
> COMPLETE_WITH("FROM SERVER");
> -------------------
Yes, this is better. The attached v2 version patch has the changes for the same.
Regards,
Vignesh
Attachments:
[application/octet-stream] v2-0001-Fix-tab-completion-after-EXCEPT-in-IMPORT-FOREIGN.patch (1.6K, 2-v2-0001-Fix-tab-completion-after-EXCEPT-in-IMPORT-FOREIGN.patch)
download | inline diff:
From 7c6e19c14d20c02b33f22531947cf9ca1cb00a21 Mon Sep 17 00:00:00 2001
From: Vignesh C <[email protected]>
Date: Wed, 15 Apr 2026 18:30:03 +0530
Subject: [PATCH v2] 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 Matches().
This ensures 'FROM SERVER' is suggested only for valid
'IMPORT FOREIGN SCHEMA' syntax.
---
src/bin/psql/tab-complete.in.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index 9990f818942..db65d130fcb 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -4900,7 +4900,7 @@ match_previous_words(int pattern_id,
else if (Matches("IMPORT", "FOREIGN", "SCHEMA", MatchAny))
COMPLETE_WITH("EXCEPT (", "FROM SERVER", "LIMIT TO (");
else if (TailMatches("LIMIT", "TO", "(*)") ||
- TailMatches("EXCEPT", "(*)"))
+ Matches("IMPORT", "FOREIGN", "SCHEMA", MatchAny, "EXCEPT", "(*)"))
COMPLETE_WITH("FROM SERVER");
else if (TailMatches("FROM", "SERVER", MatchAny))
COMPLETE_WITH("INTO");
--
2.43.0
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Fix tab completion after EXCEPT (...) in IMPORT FOREIGN SCHEMA
@ 2026-04-17 05:32 Fujii Masao <[email protected]>
parent: vignesh C <[email protected]>
0 siblings, 1 reply; 6+ messages in thread
From: Fujii Masao @ 2026-04-17 05:32 UTC (permalink / raw)
To: vignesh C <[email protected]>; +Cc: shveta malik <[email protected]>; PostgreSQL Hackers <[email protected]>
On Fri, Apr 17, 2026 at 1:32 PM vignesh C <[email protected]> wrote:
> Yes, this is better. The attached v2 version patch has the changes for the same.
Thanks for updating the patch! I've pushed it.
Regards,
--
Fujii Masao
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Fix tab completion after EXCEPT (...) in IMPORT FOREIGN SCHEMA
@ 2026-04-17 13:55 vignesh C <[email protected]>
parent: Fujii Masao <[email protected]>
0 siblings, 0 replies; 6+ messages in thread
From: vignesh C @ 2026-04-17 13:55 UTC (permalink / raw)
To: Fujii Masao <[email protected]>; +Cc: shveta malik <[email protected]>; PostgreSQL Hackers <[email protected]>
On Fri, 17 Apr 2026 at 11:02, Fujii Masao <[email protected]> wrote:
>
> On Fri, Apr 17, 2026 at 1:32 PM vignesh C <[email protected]> wrote:
> > Yes, this is better. The attached v2 version patch has the changes for the same.
>
> Thanks for updating the patch! I've pushed it.
Thanks for committing this patch.
Regards,
Vignesh
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2026-04-17 13:55 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-04-15 13:12 Fix tab completion after EXCEPT (...) in IMPORT FOREIGN SCHEMA vignesh C <[email protected]>
2026-04-16 03:59 ` shveta malik <[email protected]>
2026-04-16 17:09 ` Fujii Masao <[email protected]>
2026-04-17 04:32 ` vignesh C <[email protected]>
2026-04-17 05:32 ` Fujii Masao <[email protected]>
2026-04-17 13:55 ` vignesh C <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox