@@ -402,6 +402,24 @@ do { \
402402 matches = rl_completion_matches(text, complete_from_schema_query); \
403403} while (0)
404404
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+
405423#define COMPLETE_WITH_FUNCTION_ARG (function ) \
406424do { \
407425 set_completion_reference(function); \
@@ -1105,6 +1123,21 @@ static const SchemaQuery Query_for_trigger_of_table = {
11051123" FROM pg_catalog.pg_cursors "\
11061124" WHERE name LIKE '%s'"
11071125
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+
11081141/*
11091142 * These object types were introduced later than our support cutoff of
11101143 * server version 9.2. We use the VersionedQuery infrastructure so that
@@ -4176,6 +4209,8 @@ psql_completion(const char *text, int start, int end)
41764209 " AND nspname NOT LIKE E'pg\\\\_temp%%'" ,
41774210 "DEFAULT" );
41784211 }
4212+ else if (TailMatches ("TimeZone" , "TO|=" ))
4213+ COMPLETE_WITH_TIMEZONE_NAME ();
41794214 else
41804215 {
41814216 /* generic, type based, GUC support */
0 commit comments