From c599c43f4f7e6fae753c888da5662b420d890fb3 Mon Sep 17 00:00:00 2001
From: Andreas Karlsson <andreas@proxel.se>
Date: Fri, 15 Nov 2024 20:06:41 +0100
Subject: [PATCH 3/3] Complete first member of USING column list

---
 src/bin/psql/tab-complete.in.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index 617dd53365e..13304da74ec 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -5149,6 +5149,10 @@ match_previous_words(int pattern_id,
 			 TailMatches("JOIN", MatchAny, MatchAny, "USING") ||
 			 TailMatches("JOIN", "LATERAL", MatchAny, MatchAny, "USING"))
 		COMPLETE_WITH("(");
+	else if (TailMatches("JOIN", MatchAny, "USING", "("))
+		COMPLETE_WITH_ATTR(prev3_wd);
+	else if (TailMatches("JOIN", MatchAny, MatchAny, "USING", "("))
+		COMPLETE_WITH_ATTR(prev4_wd);
 
 /* ... AT [ LOCAL | TIME ZONE ] ... */
 	else if (TailMatches("AT"))
-- 
2.45.2

