]> granicus.if.org Git - postgresql/commitdiff
Improve tab completion for BEGIN & START|SET TRANSACTION.
authorKevin Grittner <kgrittn@postgresql.org>
Thu, 1 Sep 2016 21:10:30 +0000 (16:10 -0500)
committerKevin Grittner <kgrittn@postgresql.org>
Thu, 1 Sep 2016 21:10:30 +0000 (16:10 -0500)
Andreas Karlsson with minor change by me for SET TRANSACTION
SNAPSHOT.

src/bin/psql/tab-complete.c

index 1345e4ed80344ed52aadd9190bc8138916a73b02..019f75a37605b9c22e64e0ef05718948233d48bb 100644 (file)
@@ -1894,8 +1894,11 @@ psql_completion(const char *text, int start, int end)
        else if (Matches5("ALTER", "GROUP", MatchAny, "ADD|DROP", "USER"))
                COMPLETE_WITH_QUERY(Query_for_list_of_roles);
 
-/* BEGIN, END, ABORT */
-       else if (Matches1("BEGIN|END|ABORT"))
+/* BEGIN */
+       else if (Matches1("BEGIN"))
+               COMPLETE_WITH_LIST6("WORK", "TRANSACTION", "ISOLATION LEVEL", "READ", "DEFERRABLE", "NOT DEFERRABLE");
+/* END, ABORT */
+       else if (Matches1("END|ABORT"))
                COMPLETE_WITH_LIST2("WORK", "TRANSACTION");
 /* COMMIT */
        else if (Matches1("COMMIT"))
@@ -2762,20 +2765,36 @@ psql_completion(const char *text, int start, int end)
        else if (Matches1("SHOW"))
                COMPLETE_WITH_QUERY(Query_for_list_of_show_vars);
        /* Complete "SET TRANSACTION" */
-       else if (Matches2("SET|BEGIN|START", "TRANSACTION") ||
+       else if (Matches2("SET", "TRANSACTION"))
+               COMPLETE_WITH_LIST5("SNAPSHOT", "ISOLATION LEVEL", "READ", "DEFERRABLE", "NOT DEFERRABLE");
+       else if (Matches2("BEGIN|START", "TRANSACTION") ||
                         Matches2("BEGIN", "WORK") ||
+                        Matches1("BEGIN") ||
                  Matches5("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION"))
-               COMPLETE_WITH_LIST2("ISOLATION LEVEL", "READ");
+               COMPLETE_WITH_LIST4("ISOLATION LEVEL", "READ", "DEFERRABLE", "NOT DEFERRABLE");
+       else if (Matches3("SET|BEGIN|START", "TRANSACTION|WORK", "NOT") ||
+                        Matches2("BEGIN", "NOT") ||
+                        Matches6("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "NOT"))
+               COMPLETE_WITH_CONST("DEFERRABLE");
        else if (Matches3("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION") ||
+                        Matches2("BEGIN", "ISOLATION") ||
                         Matches6("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "ISOLATION"))
                COMPLETE_WITH_CONST("LEVEL");
-       else if (Matches4("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION", "LEVEL"))
+       else if (Matches4("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION", "LEVEL") ||
+                        Matches3("BEGIN", "ISOLATION", "LEVEL") ||
+                        Matches7("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "ISOLATION", "LEVEL"))
                COMPLETE_WITH_LIST3("READ", "REPEATABLE READ", "SERIALIZABLE");
-       else if (Matches5("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION", "LEVEL", "READ"))
+       else if (Matches5("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION", "LEVEL", "READ") ||
+                        Matches4("BEGIN", "ISOLATION", "LEVEL", "READ") ||
+                        Matches8("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "ISOLATION", "LEVEL", "READ"))
                COMPLETE_WITH_LIST2("UNCOMMITTED", "COMMITTED");
-       else if (Matches5("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION", "LEVEL", "REPEATABLE"))
+       else if (Matches5("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION", "LEVEL", "REPEATABLE") ||
+                        Matches4("BEGIN", "ISOLATION", "LEVEL", "REPEATABLE") ||
+                        Matches8("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "ISOLATION", "LEVEL", "REPEATABLE"))
                COMPLETE_WITH_CONST("READ");
-       else if (Matches3("SET|BEGIN|START", "TRANSACTION|WORK", "READ"))
+       else if (Matches3("SET|BEGIN|START", "TRANSACTION|WORK", "READ") ||
+                        Matches2("BEGIN", "READ") ||
+                        Matches6("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "READ"))
                COMPLETE_WITH_LIST2("ONLY", "WRITE");
        /* SET CONSTRAINTS */
        else if (Matches2("SET", "CONSTRAINTS"))