@@ -3599,40 +3599,49 @@ psql_completion(const char *text, int start, int end)
3599
3599
COMPLETE_WITH ("(" );
3600
3600
3601
3601
/* LOCK */
3602
- /* Complete LOCK [TABLE] with a list of tables */
3602
+ /* Complete LOCK [TABLE] [ONLY] with a list of tables */
3603
3603
else if (Matches ("LOCK" ))
3604
3604
COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tables ,
3605
- " UNION SELECT 'TABLE'" );
3605
+ " UNION SELECT 'TABLE'"
3606
+ " UNION SELECT 'ONLY'" );
3606
3607
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 );
3609
3612
/* For the following, handle the case of a single table only for now */
3610
3613
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" );
3615
3620
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" ))
3619
3623
COMPLETE_WITH ("ACCESS SHARE MODE" ,
3620
3624
"ROW SHARE MODE" , "ROW EXCLUSIVE MODE" ,
3621
3625
"SHARE UPDATE EXCLUSIVE MODE" , "SHARE MODE" ,
3622
3626
"SHARE ROW EXCLUSIVE MODE" ,
3623
3627
"EXCLUSIVE MODE" , "ACCESS EXCLUSIVE MODE" );
3624
3628
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" ))
3628
3634
COMPLETE_WITH ("EXCLUSIVE MODE" , "SHARE MODE" );
3629
3635
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" ))
3633
3638
COMPLETE_WITH ("MODE" , "ROW EXCLUSIVE MODE" ,
3634
3639
"UPDATE EXCLUSIVE MODE" );
3635
3640
3641
+ /* Complete LOCK [TABLE] [ONLY] <table> [IN lockmode MODE] with "NOWAIT" */
3642
+ else if (HeadMatches ("LOCK" ) && TailMatches ("MODE" ))
3643
+ COMPLETE_WITH ("NOWAIT" );
3644
+
3636
3645
/* NOTIFY --- can be inside EXPLAIN, RULE, etc */
3637
3646
else if (TailMatches ("NOTIFY" ))
3638
3647
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