Skip to content

Commit 9dbd94c

Browse files
committed
Adjust psql tab completion for new \d 'S' flag behavior; adjust code to
be more flexible about additional modifiers for \d commands.
1 parent e7c1105 commit 9dbd94c

File tree

1 file changed

+30
-37
lines changed

1 file changed

+30
-37
lines changed

src/bin/psql/tab-complete.c

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.181 2009/03/27 14:58:46 heikki Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.182 2009/04/06 15:50:59 momjian Exp $
77
*/
88

99
/*----------------------------------------------------------------------
@@ -431,18 +431,6 @@ static const SchemaQuery Query_for_list_of_views = {
431431
" UNION ALL SELECT 'all') ss "\
432432
" WHERE substring(name,1,%d)='%s'"
433433

434-
/*
435-
* Note: As of Pg 8.2, we no longer use relkind 's', but we keep it here
436-
* for compatibility with older servers
437-
*/
438-
#define Query_for_list_of_system_relations \
439-
"SELECT pg_catalog.quote_ident(relname) "\
440-
" FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n "\
441-
" WHERE c.relkind IN ('r', 'v', 's', 'S') "\
442-
" AND substring(pg_catalog.quote_ident(relname),1,%d)='%s' "\
443-
" AND c.relnamespace = n.oid "\
444-
" AND n.nspname = 'pg_catalog'"
445-
446434
#define Query_for_list_of_roles \
447435
" SELECT pg_catalog.quote_ident(rolname) "\
448436
" FROM pg_catalog.pg_roles "\
@@ -2183,48 +2171,53 @@ psql_completion(char *text, int start, int end)
21832171
/* TODO: \dc \dd \dl */
21842172
else if (strcmp(prev_wd, "\\connect") == 0 || strcmp(prev_wd, "\\c") == 0)
21852173
COMPLETE_WITH_QUERY(Query_for_list_of_databases);
2186-
else if (strcmp(prev_wd, "\\d") == 0 || strcmp(prev_wd, "\\d+") == 0)
2187-
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tisv, NULL);
2188-
else if (strcmp(prev_wd, "\\da") == 0)
2174+
2175+
else if (strncmp(prev_wd, "\\da", strlen("\\da")) == 0)
21892176
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_aggregates, NULL);
2190-
else if (strcmp(prev_wd, "\\db") == 0)
2177+
else if (strncmp(prev_wd, "\\db", strlen("\\db")) == 0)
21912178
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
2192-
else if (strcmp(prev_wd, "\\dD") == 0)
2179+
else if (strncmp(prev_wd, "\\dD", strlen("\\dD")) == 0)
21932180
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_domains, NULL);
2194-
else if (strcmp(prev_wd, "\\des") == 0 || strcmp(prev_wd, "\\des+") == 0)
2181+
else if (strncmp(prev_wd, "\\des", strlen("\\des")) == 0)
21952182
COMPLETE_WITH_QUERY(Query_for_list_of_servers);
2196-
else if (strcmp(prev_wd, "\\deu") == 0 || strcmp(prev_wd, "\\deu+") == 0)
2183+
else if (strncmp(prev_wd, "\\deu", strlen("\\deu")) == 0)
21972184
COMPLETE_WITH_QUERY(Query_for_list_of_user_mappings);
2198-
else if (strcmp(prev_wd, "\\dew") == 0 || strcmp(prev_wd, "\\dew+") == 0)
2185+
else if (strncmp(prev_wd, "\\dew", strlen("\\dew")) == 0)
21992186
COMPLETE_WITH_QUERY(Query_for_list_of_fdws);
2200-
else if (strcmp(prev_wd, "\\df") == 0 || strcmp(prev_wd, "\\df+") == 0)
2187+
2188+
else if (strncmp(prev_wd, "\\df", strlen("\\df")) == 0)
22012189
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_functions, NULL);
2202-
else if (strcmp(prev_wd, "\\dF") == 0 || strcmp(prev_wd, "\\dF+") == 0)
2203-
COMPLETE_WITH_QUERY(Query_for_list_of_ts_configurations);
2204-
else if (strcmp(prev_wd, "\\dFd") == 0 || strcmp(prev_wd, "\\dFd+") == 0)
2190+
else if (strncmp(prev_wd, "\\dFd", strlen("\\dFd")) == 0)
22052191
COMPLETE_WITH_QUERY(Query_for_list_of_ts_dictionaries);
2206-
else if (strcmp(prev_wd, "\\dFp") == 0 || strcmp(prev_wd, "\\dFp+") == 0)
2192+
else if (strncmp(prev_wd, "\\dFp", strlen("\\dFp")) == 0)
22072193
COMPLETE_WITH_QUERY(Query_for_list_of_ts_parsers);
2208-
else if (strcmp(prev_wd, "\\dFt") == 0 || strcmp(prev_wd, "\\dFt+") == 0)
2194+
else if (strncmp(prev_wd, "\\dFt", strlen("\\dFt")) == 0)
22092195
COMPLETE_WITH_QUERY(Query_for_list_of_ts_templates);
2210-
else if (strcmp(prev_wd, "\\di") == 0 || strcmp(prev_wd, "\\di+") == 0)
2196+
/* must be at end of \dF */
2197+
else if (strncmp(prev_wd, "\\dF", strlen("\\dF")) == 0)
2198+
COMPLETE_WITH_QUERY(Query_for_list_of_ts_configurations);
2199+
2200+
else if (strncmp(prev_wd, "\\di", strlen("\\di")) == 0)
22112201
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL);
2212-
else if (strcmp(prev_wd, "\\dn") == 0)
2202+
else if (strncmp(prev_wd, "\\dn", strlen("\\dn")) == 0)
22132203
COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
2214-
else if (strcmp(prev_wd, "\\dp") == 0 || strcmp(prev_wd, "\\z") == 0)
2204+
else if (strncmp(prev_wd, "\\dp", strlen("\\dp")) == 0)
22152205
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tsv, NULL);
2216-
else if (strcmp(prev_wd, "\\ds") == 0 || strcmp(prev_wd, "\\ds+") == 0)
2206+
else if (strncmp(prev_wd, "\\ds", strlen("\\ds")) == 0)
22172207
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_sequences, NULL);
2218-
else if (strcmp(prev_wd, "\\dS") == 0 || strcmp(prev_wd, "\\dS+") == 0)
2219-
COMPLETE_WITH_QUERY(Query_for_list_of_system_relations);
2220-
else if (strcmp(prev_wd, "\\dt") == 0 || strcmp(prev_wd, "\\dt+") == 0)
2208+
else if (strncmp(prev_wd, "\\dt", strlen("\\dt")) == 0)
22212209
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
2222-
else if (strcmp(prev_wd, "\\dT") == 0 || strcmp(prev_wd, "\\dT+") == 0)
2210+
else if (strncmp(prev_wd, "\\dT", strlen("\\dT")) == 0)
22232211
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes, NULL);
2224-
else if (strcmp(prev_wd, "\\du") == 0)
2212+
else if (strncmp(prev_wd, "\\du", strlen("\\du")) == 0)
22252213
COMPLETE_WITH_QUERY(Query_for_list_of_roles);
2226-
else if (strcmp(prev_wd, "\\dv") == 0 || strcmp(prev_wd, "\\dv+") == 0)
2214+
else if (strncmp(prev_wd, "\\dv", strlen("\\dv")) == 0)
22272215
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_views, NULL);
2216+
2217+
/* must be at end of \d list */
2218+
else if (strncmp(prev_wd, "\\d", strlen("\\d")) == 0)
2219+
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tisv, NULL);
2220+
22282221
else if (strcmp(prev_wd, "\\encoding") == 0)
22292222
COMPLETE_WITH_QUERY(Query_for_list_of_encodings);
22302223
else if (strcmp(prev_wd, "\\h") == 0 || strcmp(prev_wd, "\\help") == 0)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy