Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0b0d277

Browse files
committed
psql: Improve tab-completion for LOCK TABLE.
This commit makes psql support the tab-completion for ONLY and NOWAIT keywords of LOCK TABLE command. Author: Koyu Tanigawa Reviewed-by: Shinya Kato, Fujii Masao Discussion: https://postgr.es/m/a322684daa36319e6ebc60b541000a3a@oss.nttdata.com
1 parent e825943 commit 0b0d277

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

src/bin/psql/tab-complete.c

+26-17
Original file line numberDiff line numberDiff line change
@@ -3599,40 +3599,49 @@ psql_completion(const char *text, int start, int end)
35993599
COMPLETE_WITH("(");
36003600

36013601
/* LOCK */
3602-
/* Complete LOCK [TABLE] with a list of tables */
3602+
/* Complete LOCK [TABLE] [ONLY] with a list of tables */
36033603
else if (Matches("LOCK"))
36043604
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables,
3605-
" UNION SELECT 'TABLE'");
3605+
" UNION SELECT 'TABLE'"
3606+
" UNION SELECT 'ONLY'");
36063607
else if (Matches("LOCK", "TABLE"))
3607-
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, "");
3608-
3608+
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables,
3609+
" UNION SELECT 'ONLY'");
3610+
else if (Matches("LOCK", "TABLE", "ONLY") || Matches("LOCK", "ONLY"))
3611+
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
36093612
/* For the following, handle the case of a single table only for now */
36103613

3611-
/* Complete LOCK [TABLE] <table> with "IN" */
3612-
else if (Matches("LOCK", MatchAnyExcept("TABLE")) ||
3613-
Matches("LOCK", "TABLE", MatchAny))
3614-
COMPLETE_WITH("IN");
3614+
/* Complete LOCK [TABLE] [ONLY] <table> with IN or NOWAIT */
3615+
else if (Matches("LOCK", MatchAnyExcept("TABLE|ONLY")) ||
3616+
Matches("LOCK", "TABLE", MatchAnyExcept("ONLY")) ||
3617+
Matches("LOCK", "ONLY", MatchAny) ||
3618+
Matches("LOCK", "TABLE", "ONLY", MatchAny))
3619+
COMPLETE_WITH("IN", "NOWAIT");
36153620

3616-
/* Complete LOCK [TABLE] <table> IN with a lock mode */
3617-
else if (Matches("LOCK", MatchAny, "IN") ||
3618-
Matches("LOCK", "TABLE", MatchAny, "IN"))
3621+
/* Complete LOCK [TABLE] [ONLY] <table> IN with a lock mode */
3622+
else if (HeadMatches("LOCK") && TailMatches("IN"))
36193623
COMPLETE_WITH("ACCESS SHARE MODE",
36203624
"ROW SHARE MODE", "ROW EXCLUSIVE MODE",
36213625
"SHARE UPDATE EXCLUSIVE MODE", "SHARE MODE",
36223626
"SHARE ROW EXCLUSIVE MODE",
36233627
"EXCLUSIVE MODE", "ACCESS EXCLUSIVE MODE");
36243628

3625-
/* Complete LOCK [TABLE] <table> IN ACCESS|ROW with rest of lock mode */
3626-
else if (Matches("LOCK", MatchAny, "IN", "ACCESS|ROW") ||
3627-
Matches("LOCK", "TABLE", MatchAny, "IN", "ACCESS|ROW"))
3629+
/*
3630+
* Complete LOCK [TABLE][ONLY] <table> IN ACCESS|ROW with rest of lock
3631+
* mode
3632+
*/
3633+
else if (HeadMatches("LOCK") && TailMatches("IN", "ACCESS|ROW"))
36283634
COMPLETE_WITH("EXCLUSIVE MODE", "SHARE MODE");
36293635

3630-
/* Complete LOCK [TABLE] <table> IN SHARE with rest of lock mode */
3631-
else if (Matches("LOCK", MatchAny, "IN", "SHARE") ||
3632-
Matches("LOCK", "TABLE", MatchAny, "IN", "SHARE"))
3636+
/* Complete LOCK [TABLE] [ONLY] <table> IN SHARE with rest of lock mode */
3637+
else if (HeadMatches("LOCK") && TailMatches("IN", "SHARE"))
36333638
COMPLETE_WITH("MODE", "ROW EXCLUSIVE MODE",
36343639
"UPDATE EXCLUSIVE MODE");
36353640

3641+
/* Complete LOCK [TABLE] [ONLY] <table> [IN lockmode MODE] with "NOWAIT" */
3642+
else if (HeadMatches("LOCK") && TailMatches("MODE"))
3643+
COMPLETE_WITH("NOWAIT");
3644+
36363645
/* NOTIFY --- can be inside EXPLAIN, RULE, etc */
36373646
else if (TailMatches("NOTIFY"))
36383647
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'");

0 commit comments

Comments
 (0)