@@ -257,13 +257,22 @@ do { \
257
257
} while (0)
258
258
259
259
#define COMPLETE_WITH_QUERY_VERBATIM (query ) \
260
+ COMPLETE_WITH_QUERY_VERBATIM_LIST(query, NULL)
261
+
262
+ #define COMPLETE_WITH_QUERY_VERBATIM_LIST (query , list ) \
260
263
do { \
261
264
completion_charp = query; \
262
- completion_charpp = NULL ; \
265
+ completion_charpp = list ; \
263
266
completion_verbatim = true; \
264
267
matches = rl_completion_matches(text, complete_from_query); \
265
268
} while (0)
266
269
270
+ #define COMPLETE_WITH_QUERY_VERBATIM_PLUS (query , ...) \
271
+ do { \
272
+ static const char *const list[] = { __VA_ARGS__, NULL }; \
273
+ COMPLETE_WITH_QUERY_VERBATIM_LIST(query, list); \
274
+ } while (0)
275
+
267
276
#define COMPLETE_WITH_VERSIONED_QUERY (query ) \
268
277
COMPLETE_WITH_VERSIONED_QUERY_LIST(query, NULL)
269
278
@@ -1273,6 +1282,7 @@ static char *_complete_from_query(const char *simple_query,
1273
1282
bool verbatim ,
1274
1283
const char * text , int state );
1275
1284
static void set_completion_reference (const char * word );
1285
+ static void set_completion_reference_verbatim (const char * word );
1276
1286
static char * complete_from_list (const char * text , int state );
1277
1287
static char * complete_from_const (const char * text , int state );
1278
1288
static void append_variable_names (char * * * varnames , int * nvars ,
@@ -2058,8 +2068,8 @@ psql_completion(const char *text, int start, int end)
2058
2068
else if (Matches ("ALTER" , "SYSTEM" ))
2059
2069
COMPLETE_WITH ("SET" , "RESET" );
2060
2070
else if (Matches ("ALTER" , "SYSTEM" , "SET|RESET" ))
2061
- COMPLETE_WITH_QUERY_PLUS (Query_for_list_of_alter_system_set_vars ,
2062
- "ALL" );
2071
+ COMPLETE_WITH_QUERY_VERBATIM_PLUS (Query_for_list_of_alter_system_set_vars ,
2072
+ "ALL" );
2063
2073
else if (Matches ("ALTER" , "SYSTEM" , "SET" , MatchAny ))
2064
2074
COMPLETE_WITH ("TO" );
2065
2075
/* ALTER VIEW <name> */
@@ -4038,17 +4048,17 @@ psql_completion(const char *text, int start, int end)
4038
4048
/* SET, RESET, SHOW */
4039
4049
/* Complete with a variable name */
4040
4050
else if (TailMatches ("SET|RESET" ) && !TailMatches ("UPDATE" , MatchAny , "SET" ))
4041
- COMPLETE_WITH_QUERY_PLUS (Query_for_list_of_set_vars ,
4042
- "CONSTRAINTS" ,
4043
- "TRANSACTION" ,
4044
- "SESSION" ,
4045
- "ROLE" ,
4046
- "TABLESPACE" ,
4047
- "ALL" );
4051
+ COMPLETE_WITH_QUERY_VERBATIM_PLUS (Query_for_list_of_set_vars ,
4052
+ "CONSTRAINTS" ,
4053
+ "TRANSACTION" ,
4054
+ "SESSION" ,
4055
+ "ROLE" ,
4056
+ "TABLESPACE" ,
4057
+ "ALL" );
4048
4058
else if (Matches ("SHOW" ))
4049
- COMPLETE_WITH_QUERY_PLUS (Query_for_list_of_show_vars ,
4050
- "SESSION AUTHORIZATION" ,
4051
- "ALL" );
4059
+ COMPLETE_WITH_QUERY_VERBATIM_PLUS (Query_for_list_of_show_vars ,
4060
+ "SESSION AUTHORIZATION" ,
4061
+ "ALL" );
4052
4062
else if (Matches ("SHOW" , "SESSION" ))
4053
4063
COMPLETE_WITH ("AUTHORIZATION" );
4054
4064
/* Complete "SET TRANSACTION" */
@@ -4150,7 +4160,7 @@ psql_completion(const char *text, int start, int end)
4150
4160
{
4151
4161
if (strcmp (guctype , "enum" ) == 0 )
4152
4162
{
4153
- set_completion_reference (prev2_wd );
4163
+ set_completion_reference_verbatim (prev2_wd );
4154
4164
COMPLETE_WITH_QUERY_PLUS (Query_for_values_of_enum_GUC ,
4155
4165
"DEFAULT" );
4156
4166
}
@@ -4707,7 +4717,7 @@ complete_from_versioned_schema_query(const char *text, int state)
4707
4717
* version of the string provided in completion_ref_object. If there is a
4708
4718
* third '%s', it will be replaced by a suitably-escaped version of the string
4709
4719
* provided in completion_ref_schema. Those strings should be set up
4710
- * by calling set_completion_reference() .
4720
+ * by calling set_completion_reference or set_completion_reference_verbatim .
4711
4721
* Simple queries should return a single column of matches. If "verbatim"
4712
4722
* is true, the matches are returned as-is; otherwise, they are taken to
4713
4723
* be SQL identifiers and quoted if necessary.
@@ -5037,11 +5047,7 @@ _complete_from_query(const char *simple_query,
5037
5047
if (pg_strncasecmp (text , item , strlen (text )) == 0 )
5038
5048
{
5039
5049
num_keywords ++ ;
5040
- /* Match keyword case if we are returning only keywords */
5041
- if (num_schema_only == 0 && num_query_other == 0 )
5042
- return pg_strdup_keyword_case (item , text );
5043
- else
5044
- return pg_strdup (item );
5050
+ return pg_strdup_keyword_case (item , text );
5045
5051
}
5046
5052
}
5047
5053
}
@@ -5059,11 +5065,7 @@ _complete_from_query(const char *simple_query,
5059
5065
if (pg_strncasecmp (text , item , strlen (text )) == 0 )
5060
5066
{
5061
5067
num_keywords ++ ;
5062
- /* Match keyword case if we are returning only keywords */
5063
- if (num_schema_only == 0 && num_query_other == 0 )
5064
- return pg_strdup_keyword_case (item , text );
5065
- else
5066
- return pg_strdup (item );
5068
+ return pg_strdup_keyword_case (item , text );
5067
5069
}
5068
5070
}
5069
5071
}
@@ -5100,6 +5102,17 @@ set_completion_reference(const char *word)
5100
5102
& schemaquoted , & objectquoted );
5101
5103
}
5102
5104
5105
+ /*
5106
+ * Set up completion_ref_object when it should just be
5107
+ * the given word verbatim.
5108
+ */
5109
+ static void
5110
+ set_completion_reference_verbatim (const char * word )
5111
+ {
5112
+ completion_ref_schema = NULL ;
5113
+ completion_ref_object = pg_strdup (word );
5114
+ }
5115
+
5103
5116
5104
5117
/*
5105
5118
* This function returns in order one of a fixed, NULL pointer terminated list
0 commit comments