diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 5cd5838668..ecae9df8ed 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -3599,40 +3599,49 @@ psql_completion(const char *text, int start, int end) COMPLETE_WITH("("); /* LOCK */ - /* Complete LOCK [TABLE] with a list of tables */ + /* Complete LOCK [TABLE] [ONLY] with a list of tables */ else if (Matches("LOCK")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, - " UNION SELECT 'TABLE'"); + " UNION SELECT 'TABLE'" + " UNION SELECT 'ONLY'"); else if (Matches("LOCK", "TABLE")) - COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, ""); - + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, + " UNION SELECT 'ONLY'"); + else if (Matches("LOCK", "TABLE", "ONLY") || Matches("LOCK", "ONLY")) + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL); /* For the following, handle the case of a single table only for now */ - /* Complete LOCK [TABLE] with "IN" */ - else if (Matches("LOCK", MatchAnyExcept("TABLE")) || - Matches("LOCK", "TABLE", MatchAny)) - COMPLETE_WITH("IN"); + /* Complete LOCK [TABLE] [ONLY]
with IN or NOWAIT */ + else if (Matches("LOCK", MatchAnyExcept("TABLE|ONLY")) || + Matches("LOCK", "TABLE", MatchAnyExcept("ONLY")) || + Matches("LOCK", "ONLY", MatchAny) || + Matches("LOCK", "TABLE", "ONLY", MatchAny)) + COMPLETE_WITH("IN", "NOWAIT"); - /* Complete LOCK [TABLE]
IN with a lock mode */ - else if (Matches("LOCK", MatchAny, "IN") || - Matches("LOCK", "TABLE", MatchAny, "IN")) + /* Complete LOCK [TABLE] [ONLY]
IN with a lock mode */ + else if (HeadMatches("LOCK") && TailMatches("IN")) COMPLETE_WITH("ACCESS SHARE MODE", "ROW SHARE MODE", "ROW EXCLUSIVE MODE", "SHARE UPDATE EXCLUSIVE MODE", "SHARE MODE", "SHARE ROW EXCLUSIVE MODE", "EXCLUSIVE MODE", "ACCESS EXCLUSIVE MODE"); - /* Complete LOCK [TABLE]
IN ACCESS|ROW with rest of lock mode */ - else if (Matches("LOCK", MatchAny, "IN", "ACCESS|ROW") || - Matches("LOCK", "TABLE", MatchAny, "IN", "ACCESS|ROW")) + /* + * Complete LOCK [TABLE][ONLY]
IN ACCESS|ROW with rest of lock + * mode + */ + else if (HeadMatches("LOCK") && TailMatches("IN", "ACCESS|ROW")) COMPLETE_WITH("EXCLUSIVE MODE", "SHARE MODE"); - /* Complete LOCK [TABLE]
IN SHARE with rest of lock mode */ - else if (Matches("LOCK", MatchAny, "IN", "SHARE") || - Matches("LOCK", "TABLE", MatchAny, "IN", "SHARE")) + /* Complete LOCK [TABLE] [ONLY]
IN SHARE with rest of lock mode */ + else if (HeadMatches("LOCK") && TailMatches("IN", "SHARE")) COMPLETE_WITH("MODE", "ROW EXCLUSIVE MODE", "UPDATE EXCLUSIVE MODE"); + /* Complete LOCK [TABLE] [ONLY]
[IN lockmode MODE] with "NOWAIT" */ + else if (HeadMatches("LOCK") && TailMatches("MODE")) + COMPLETE_WITH("NOWAIT"); + /* NOTIFY --- can be inside EXPLAIN, RULE, etc */ else if (TailMatches("NOTIFY")) COMPLETE_WITH_QUERY("SELECT pg_catalog.quote_ident(channel) FROM pg_catalog.pg_listening_channels() AS channel WHERE substring(pg_catalog.quote_ident(channel),1,%d)='%s'");