Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7fa3db3

Browse files
committed
psql: handle tab completion of timezone names after "SET TIMEZONE TO".
Dagfinn Ilmari Mannsåker and Tom LaneDiscussion:https://postgr.es/m/87k0curq0w.fsf@wibble.ilmari.org
1 parentba9a7e3 commit7fa3db3

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

‎src/bin/psql/t/010_tab_completion.pl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,19 @@ sub clear_line
338338

339339
clear_line();
340340

341+
# check timezone name completion
342+
check_completion(
343+
"SET timezone TO am\t",
344+
qr|'America/|,
345+
"offer partial timezone name");
346+
347+
check_completion(
348+
"new_\t",
349+
qr|New_York|,
350+
"complete partial timezone name");
351+
352+
clear_line();
353+
341354
# check completion of a keyword offered in addition to object names;
342355
# such a keyword should obey COMP_KEYWORD_CASE
343356
foreach (

‎src/bin/psql/tab-complete.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
#defineCOMPLETE_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
#defineCOMPLETE_WITH_FUNCTION_ARG(function) \
406424
do { \
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+
#defineQuery_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+
#defineQuery_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+
#defineQuery_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+
elseif (TailMatches("TimeZone","TO|="))
4213+
COMPLETE_WITH_TIMEZONE_NAME();
41794214
else
41804215
{
41814216
/* generic, type based, GUC support */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp