@@ -402,6 +402,24 @@ do { \
402
402
matches = rl_completion_matches(text, complete_from_schema_query); \
403
403
} while (0)
404
404
405
+ /*
406
+ * Timezone completion is mostly like enum label completion, but we work
407
+ * a little harder since this is a more common use-case.
408
+ */
409
+ #define COMPLETE_WITH_TIMEZONE_NAME () \
410
+ do { \
411
+ static const char *const list[] = { "DEFAULT", NULL }; \
412
+ if (text[0] == '\'') \
413
+ completion_charp = Query_for_list_of_timezone_names_quoted_in; \
414
+ else if (start == 0 || rl_line_buffer[start - 1] != '\'') \
415
+ completion_charp = Query_for_list_of_timezone_names_quoted_out; \
416
+ else \
417
+ completion_charp = Query_for_list_of_timezone_names_unquoted; \
418
+ completion_charpp = list; \
419
+ completion_verbatim = true; \
420
+ matches = rl_completion_matches(text, complete_from_query); \
421
+ } while (0)
422
+
405
423
#define COMPLETE_WITH_FUNCTION_ARG (function ) \
406
424
do { \
407
425
set_completion_reference(function); \
@@ -1105,6 +1123,21 @@ static const SchemaQuery Query_for_trigger_of_table = {
1105
1123
" FROM pg_catalog.pg_cursors "\
1106
1124
" WHERE name LIKE '%s'"
1107
1125
1126
+ #define Query_for_list_of_timezone_names_unquoted \
1127
+ " SELECT name "\
1128
+ " FROM pg_catalog.pg_timezone_names() "\
1129
+ " WHERE pg_catalog.lower(name) LIKE pg_catalog.lower('%s')"
1130
+
1131
+ #define Query_for_list_of_timezone_names_quoted_out \
1132
+ "SELECT pg_catalog.quote_literal(name) AS name "\
1133
+ " FROM pg_catalog.pg_timezone_names() "\
1134
+ " WHERE pg_catalog.lower(name) LIKE pg_catalog.lower('%s')"
1135
+
1136
+ #define Query_for_list_of_timezone_names_quoted_in \
1137
+ "SELECT pg_catalog.quote_literal(name) AS name "\
1138
+ " FROM pg_catalog.pg_timezone_names() "\
1139
+ " WHERE pg_catalog.quote_literal(pg_catalog.lower(name)) LIKE pg_catalog.lower('%s')"
1140
+
1108
1141
/*
1109
1142
* These object types were introduced later than our support cutoff of
1110
1143
* server version 9.2. We use the VersionedQuery infrastructure so that
@@ -4176,6 +4209,8 @@ psql_completion(const char *text, int start, int end)
4176
4209
" AND nspname NOT LIKE E'pg\\\\_temp%%'" ,
4177
4210
"DEFAULT" );
4178
4211
}
4212
+ else if (TailMatches ("TimeZone" , "TO|=" ))
4213
+ COMPLETE_WITH_TIMEZONE_NAME ();
4179
4214
else
4180
4215
{
4181
4216
/* generic, type based, GUC support */
0 commit comments