]> granicus.if.org Git - postgresql/commitdiff
Improve tab completion of CREATE EVENT TRIGGER in psql
authorMichael Paquier <michael@paquier.xyz>
Fri, 26 Oct 2018 04:46:20 +0000 (13:46 +0900)
committerMichael Paquier <michael@paquier.xyz>
Fri, 26 Oct 2018 04:46:20 +0000 (13:46 +0900)
This adds tab completion of the clauses WHEN and EXECUTE
FUNCTION|PROCEDURE clauses to CREATE EVENT TRIGGER, similar to CREATE
TRIGGER in the previous commit.  This has version-dependent logic so as
FUNCTION is chosen over PROCEDURE for 11 and newer versions.

Author: Dagfinn Ilmari MannsÃ¥ker
Reviewed-by: Tom Lane, Michael Paquier
Discussion: https://postgr.es/m/d8jmur4q4yc.fsf@dalvik.ping.uio.no

src/bin/psql/tab-complete.c

index 4200574079867015f9c3b3af2a17e0759be80485..a980f92e11bed62ab8fc79403a9fc75d26cf16ef 100644 (file)
@@ -2608,6 +2608,29 @@ psql_completion(const char *text, int start, int end)
        /* Complete CREATE EVENT TRIGGER <name> ON with event_type */
        else if (Matches("CREATE", "EVENT", "TRIGGER", MatchAny, "ON"))
                COMPLETE_WITH("ddl_command_start", "ddl_command_end", "sql_drop");
+       /*
+        * Complete CREATE EVENT TRIGGER <name> ON <event_type>.  EXECUTE FUNCTION
+        * is the recommended grammar instead of EXECUTE PROCEDURE in version 11
+        * and upwards.
+        */
+       else if (Matches("CREATE", "EVENT", "TRIGGER", MatchAny, "ON", MatchAny))
+       {
+               if (pset.sversion >= 110000)
+                       COMPLETE_WITH("WHEN TAG IN (", "EXECUTE FUNCTION");
+               else
+                       COMPLETE_WITH("WHEN TAG IN (", "EXECUTE PROCEDURE");
+       }
+       else if (HeadMatches("CREATE", "EVENT", "TRIGGER") &&
+                        TailMatches("WHEN|AND", MatchAny, "IN", "(*)"))
+       {
+               if (pset.sversion >= 110000)
+                       COMPLETE_WITH("EXECUTE FUNCTION");
+               else
+                       COMPLETE_WITH("EXECUTE PROCEDURE");
+       }
+       else if (HeadMatches("CREATE", "EVENT", "TRIGGER") &&
+                        TailMatches("EXECUTE", "FUNCTION|PROCEDURE"))
+               COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_functions, NULL);
 
 /* DEALLOCATE */
        else if (Matches("DEALLOCATE"))