psql: Tab completion for JOIN ... ON/USING
authorTomas Vondra <tomas.vondra@postgresql.org>
Mon, 16 Dec 2024 17:08:30 +0000 (18:08 +0100)
committerTomas Vondra <tomas.vondra@postgresql.org>
Mon, 16 Dec 2024 17:47:03 +0000 (18:47 +0100)
Offer ON/USING clauses for join types that require join conditions (i.e.
anything except for NATURAL/CROSS joins).

Author: Andreas Karlsson
Reviewed-By: Tomas Vondra
Discussion: https://postgr.es/m/3a7e27bc-d6ed-4cb0-9b21-f21143fc1b37@proxel.se

src/bin/psql/tab-complete.in.c

index 6a9c5e240fb06460aa66069f9e6b952f5c3a862d..e9af7b37ac88e8dfc78a43d89259eed82139767b 100644 (file)
@@ -5167,6 +5167,18 @@ match_previous_words(int pattern_id,
 /* ... JOIN ... */
        else if (TailMatches("JOIN"))
                COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_selectables, "LATERAL");
+       else if (TailMatches("JOIN", MatchAny) && !TailMatches("CROSS|NATURAL", "JOIN", MatchAny))
+               COMPLETE_WITH("ON", "USING (");
+       else if (TailMatches("JOIN", MatchAny, MatchAny) &&
+                        !TailMatches("CROSS|NATURAL", "JOIN", MatchAny, MatchAny) && !TailMatches("ON|USING"))
+               COMPLETE_WITH("ON", "USING (");
+       else if (TailMatches("JOIN", "LATERAL", MatchAny, MatchAny) &&
+                        !TailMatches("CROSS|NATURAL", "JOIN", "LATERAL", MatchAny, MatchAny) && !TailMatches("ON|USING"))
+               COMPLETE_WITH("ON", "USING (");
+       else if (TailMatches("JOIN", MatchAny, "USING") ||
+                        TailMatches("JOIN", MatchAny, MatchAny, "USING") ||
+                        TailMatches("JOIN", "LATERAL", MatchAny, MatchAny, "USING"))
+               COMPLETE_WITH("(");
 
 /* ... AT [ LOCAL | TIME ZONE ] ... */
        else if (TailMatches("AT"))