Subject: Fix tab completion after EXCEPT (...) in IMPORT FOREIGN SCHEMA

From: vignesh C <[email-masked]>
Date: Wed, 15 Apr 2026 18:42:47 +0530

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

---

From: shveta malik <[email-masked]>
Date: Thu, 16 Apr 2026 09:29:41 +0530

> existing LIMIT TO (...) behavior.

I can reproduce the problem without the patch. The patch looks good to me.

thanks
Shveta

---

From: Fujii Masao <[email-masked]>
Date: Fri, 17 Apr 2026 02:09:32 +0900

> > 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

---

From: vignesh C <[email-masked]>
Date: Fri, 17 Apr 2026 10:02:04 +0530

> to keep a single condition?, for example:

Yes, this is better. The attached v2 version patch has the changes for the same.

Regards,
Vignesh

---

From: Fujii Masao <[email-masked]>
Date: Fri, 17 Apr 2026 14:32:25 +0900

> 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

---

From: vignesh C <[email-masked]>
Date: Fri, 17 Apr 2026 19:25:42 +0530

> Thanks for updating the patch! I've pushed it.

Thanks for committing this patch.

Regards,
Vignesh