@@ -1320,9 +1320,11 @@ initialize_readline(void)
1320
1320
rl_basic_word_break_characters = WORD_BREAKS ;
1321
1321
1322
1322
/*
1323
- * We should include '"' in rl_completer_quote_characters too, but that
1324
- * will require some upgrades to how we handle quoted identifiers, so
1325
- * that's for another day.
1323
+ * Ideally we'd include '"' in rl_completer_quote_characters too, which
1324
+ * should allow us to complete quoted identifiers that include spaces.
1325
+ * However, the library support for rl_completer_quote_characters is
1326
+ * presently too inconsistent to want to mess with that. (Note in
1327
+ * particular that libedit has this variable but completely ignores it.)
1326
1328
*/
1327
1329
rl_completer_quote_characters = "'" ;
1328
1330
@@ -2059,7 +2061,7 @@ psql_completion(const char *text, int start, int end)
2059
2061
COMPLETE_WITH ("SET" , "RESET" );
2060
2062
else if (Matches ("ALTER" , "SYSTEM" , "SET|RESET" ))
2061
2063
COMPLETE_WITH_QUERY_PLUS (Query_for_list_of_alter_system_set_vars ,
2062
- "all " );
2064
+ "ALL " );
2063
2065
else if (Matches ("ALTER" , "SYSTEM" , "SET" , MatchAny ))
2064
2066
COMPLETE_WITH ("TO" );
2065
2067
/* ALTER VIEW <name> */
@@ -4039,16 +4041,18 @@ psql_completion(const char *text, int start, int end)
4039
4041
/* Complete with a variable name */
4040
4042
else if (TailMatches ("SET|RESET" ) && !TailMatches ("UPDATE" , MatchAny , "SET" ))
4041
4043
COMPLETE_WITH_QUERY_PLUS (Query_for_list_of_set_vars ,
4042
- "constraints " ,
4043
- "transaction " ,
4044
- "session " ,
4045
- "role " ,
4046
- "tablespace " ,
4047
- "all " );
4044
+ "CONSTRAINTS " ,
4045
+ "TRANSACTION " ,
4046
+ "SESSION " ,
4047
+ "ROLE " ,
4048
+ "TABLESPACE " ,
4049
+ "ALL " );
4048
4050
else if (Matches ("SHOW" ))
4049
4051
COMPLETE_WITH_QUERY_PLUS (Query_for_list_of_show_vars ,
4050
- "session authorization" ,
4051
- "all" );
4052
+ "SESSION AUTHORIZATION" ,
4053
+ "ALL" );
4054
+ else if (Matches ("SHOW" , "SESSION" ))
4055
+ COMPLETE_WITH ("AUTHORIZATION" );
4052
4056
/* Complete "SET TRANSACTION" */
4053
4057
else if (Matches ("SET" , "TRANSACTION" ))
4054
4058
COMPLETE_WITH ("SNAPSHOT" , "ISOLATION LEVEL" , "READ" , "DEFERRABLE" , "NOT DEFERRABLE" );
@@ -4742,7 +4746,8 @@ _complete_from_query(const char *simple_query,
4742
4746
{
4743
4747
static int list_index ,
4744
4748
num_schema_only ,
4745
- num_other ;
4749
+ num_query_other ,
4750
+ num_keywords ;
4746
4751
static PGresult * result = NULL ;
4747
4752
static bool non_empty_object ;
4748
4753
static bool schemaquoted ;
@@ -4765,7 +4770,8 @@ _complete_from_query(const char *simple_query,
4765
4770
/* Reset static state, ensuring no memory leaks */
4766
4771
list_index = 0 ;
4767
4772
num_schema_only = 0 ;
4768
- num_other = 0 ;
4773
+ num_query_other = 0 ;
4774
+ num_keywords = 0 ;
4769
4775
PQclear (result );
4770
4776
result = NULL ;
4771
4777
@@ -4986,7 +4992,10 @@ _complete_from_query(const char *simple_query,
4986
4992
4987
4993
/* In verbatim mode, we return all the items as-is */
4988
4994
if (verbatim )
4995
+ {
4996
+ num_query_other ++ ;
4989
4997
return pg_strdup (item );
4998
+ }
4990
4999
4991
5000
/*
4992
5001
* In normal mode, a name requiring quoting will be returned only
@@ -5007,7 +5016,7 @@ _complete_from_query(const char *simple_query,
5007
5016
if (item == NULL && nsp != NULL )
5008
5017
num_schema_only ++ ;
5009
5018
else
5010
- num_other ++ ;
5019
+ num_query_other ++ ;
5011
5020
5012
5021
return requote_identifier (nsp , item , schemaquoted , objectquoted );
5013
5022
}
@@ -5031,8 +5040,12 @@ _complete_from_query(const char *simple_query,
5031
5040
list_index ++ ;
5032
5041
if (pg_strncasecmp (text , item , strlen (text )) == 0 )
5033
5042
{
5034
- num_other ++ ;
5035
- return pg_strdup (item );
5043
+ num_keywords ++ ;
5044
+ /* Match keyword case if we are returning only keywords */
5045
+ if (num_schema_only == 0 && num_query_other == 0 )
5046
+ return pg_strdup_keyword_case (item , text );
5047
+ else
5048
+ return pg_strdup (item );
5036
5049
}
5037
5050
}
5038
5051
}
@@ -5049,8 +5062,12 @@ _complete_from_query(const char *simple_query,
5049
5062
list_index ++ ;
5050
5063
if (pg_strncasecmp (text , item , strlen (text )) == 0 )
5051
5064
{
5052
- num_other ++ ;
5053
- return pg_strdup (item );
5065
+ num_keywords ++ ;
5066
+ /* Match keyword case if we are returning only keywords */
5067
+ if (num_schema_only == 0 && num_query_other == 0 )
5068
+ return pg_strdup_keyword_case (item , text );
5069
+ else
5070
+ return pg_strdup (item );
5054
5071
}
5055
5072
}
5056
5073
}
@@ -5062,7 +5079,7 @@ _complete_from_query(const char *simple_query,
5062
5079
* completion subject text, which is not what we want.
5063
5080
*/
5064
5081
#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
5065
- if (num_schema_only > 0 && num_other == 0 )
5082
+ if (num_schema_only > 0 && num_query_other == 0 && num_keywords == 0 )
5066
5083
rl_completion_append_character = '\0' ;
5067
5084
#endif
5068
5085
0 commit comments