@@ -446,16 +446,6 @@ static const SchemaQuery Query_for_list_of_functions[] = {
446446 }
447447};
448448
449- static const SchemaQuery Query_for_list_of_indexes = {
450- .catname = "pg_catalog.pg_class c" ,
451- .selcondition =
452- "c.relkind IN (" CppAsString2 (RELKIND_INDEX ) ", "
453- CppAsString2 (RELKIND_PARTITIONED_INDEX ) ")" ,
454- .viscondition = "pg_catalog.pg_table_is_visible(c.oid)" ,
455- .namespace = "c.relnamespace" ,
456- .result = "pg_catalog.quote_ident(c.relname)" ,
457- };
458-
459449static const SchemaQuery Query_for_list_of_procedures [] = {
460450 {
461451 .min_server_version = 110000 ,
@@ -512,35 +502,55 @@ static const SchemaQuery Query_for_list_of_partitioned_tables = {
512502 .result = "pg_catalog.quote_ident(c.relname)" ,
513503};
514504
515- static const SchemaQuery Query_for_list_of_constraints_with_schema = {
516- .catname = "pg_catalog.pg_constraint c" ,
517- .selcondition = "c.conrelid <> 0 " ,
518- .viscondition = "true" , /* there is no pg_constraint_is_visible */
519- .namespace = "c.connamespace " ,
520- .result = "pg_catalog.quote_ident(c.conname )" ,
505+ static const SchemaQuery Query_for_list_of_views = {
506+ .catname = "pg_catalog.pg_class c" ,
507+ .selcondition = "c.relkind IN (" CppAsString2 ( RELKIND_VIEW ) ") " ,
508+ .viscondition = "pg_catalog.pg_table_is_visible(c.oid)" ,
509+ .namespace = "c.relnamespace " ,
510+ .result = "pg_catalog.quote_ident(c.relname )" ,
521511};
522512
523- /* Relations supporting INSERT, UPDATE or DELETE */
524- static const SchemaQuery Query_for_list_of_updatables = {
513+ static const SchemaQuery Query_for_list_of_matviews = {
514+ .catname = "pg_catalog.pg_class c" ,
515+ .selcondition = "c.relkind IN (" CppAsString2 (RELKIND_MATVIEW ) ")" ,
516+ .viscondition = "pg_catalog.pg_table_is_visible(c.oid)" ,
517+ .namespace = "c.relnamespace" ,
518+ .result = "pg_catalog.quote_ident(c.relname)" ,
519+ };
520+
521+ static const SchemaQuery Query_for_list_of_indexes = {
525522 .catname = "pg_catalog.pg_class c" ,
526523 .selcondition =
527- "c.relkind IN (" CppAsString2 (RELKIND_RELATION ) ", "
528- CppAsString2 (RELKIND_FOREIGN_TABLE ) ", "
529- CppAsString2 (RELKIND_VIEW ) ", "
530- CppAsString2 (RELKIND_PARTITIONED_TABLE ) ")" ,
524+ "c.relkind IN (" CppAsString2 (RELKIND_INDEX ) ", "
525+ CppAsString2 (RELKIND_PARTITIONED_INDEX ) ")" ,
531526 .viscondition = "pg_catalog.pg_table_is_visible(c.oid)" ,
532527 .namespace = "c.relnamespace" ,
533528 .result = "pg_catalog.quote_ident(c.relname)" ,
534529};
535530
531+ /* All relations */
536532static const SchemaQuery Query_for_list_of_relations = {
537533 .catname = "pg_catalog.pg_class c" ,
538534 .viscondition = "pg_catalog.pg_table_is_visible(c.oid)" ,
539535 .namespace = "c.relnamespace" ,
540536 .result = "pg_catalog.quote_ident(c.relname)" ,
541537};
542538
543- static const SchemaQuery Query_for_list_of_tsvmf = {
539+ /* Relations supporting INSERT, UPDATE or DELETE */
540+ static const SchemaQuery Query_for_list_of_updatables = {
541+ .catname = "pg_catalog.pg_class c" ,
542+ .selcondition =
543+ "c.relkind IN (" CppAsString2 (RELKIND_RELATION ) ", "
544+ CppAsString2 (RELKIND_FOREIGN_TABLE ) ", "
545+ CppAsString2 (RELKIND_VIEW ) ", "
546+ CppAsString2 (RELKIND_PARTITIONED_TABLE ) ")" ,
547+ .viscondition = "pg_catalog.pg_table_is_visible(c.oid)" ,
548+ .namespace = "c.relnamespace" ,
549+ .result = "pg_catalog.quote_ident(c.relname)" ,
550+ };
551+
552+ /* Relations supporting SELECT */
553+ static const SchemaQuery Query_for_list_of_selectables = {
544554 .catname = "pg_catalog.pg_class c" ,
545555 .selcondition =
546556 "c.relkind IN (" CppAsString2 (RELKIND_RELATION ) ", "
@@ -554,7 +564,11 @@ static const SchemaQuery Query_for_list_of_tsvmf = {
554564 .result = "pg_catalog.quote_ident(c.relname)" ,
555565};
556566
557- static const SchemaQuery Query_for_list_of_tmf = {
567+ /* Relations supporting GRANT are currently same as those supporting SELECT */
568+ #define Query_for_list_of_grantables Query_for_list_of_selectables
569+
570+ /* Relations supporting ANALYZE */
571+ static const SchemaQuery Query_for_list_of_analyzables = {
558572 .catname = "pg_catalog.pg_class c" ,
559573 .selcondition =
560574 "c.relkind IN (" CppAsString2 (RELKIND_RELATION ) ", "
@@ -566,7 +580,8 @@ static const SchemaQuery Query_for_list_of_tmf = {
566580 .result = "pg_catalog.quote_ident(c.relname)" ,
567581};
568582
569- static const SchemaQuery Query_for_list_of_tpm = {
583+ /* Relations supporting index creation */
584+ static const SchemaQuery Query_for_list_of_indexables = {
570585 .catname = "pg_catalog.pg_class c" ,
571586 .selcondition =
572587 "c.relkind IN (" CppAsString2 (RELKIND_RELATION ) ", "
@@ -577,7 +592,8 @@ static const SchemaQuery Query_for_list_of_tpm = {
577592 .result = "pg_catalog.quote_ident(c.relname)" ,
578593};
579594
580- static const SchemaQuery Query_for_list_of_tm = {
595+ /* Relations supporting VACUUM */
596+ static const SchemaQuery Query_for_list_of_vacuumables = {
581597 .catname = "pg_catalog.pg_class c" ,
582598 .selcondition =
583599 "c.relkind IN (" CppAsString2 (RELKIND_RELATION ) ", "
@@ -587,20 +603,15 @@ static const SchemaQuery Query_for_list_of_tm = {
587603 .result = "pg_catalog.quote_ident(c.relname)" ,
588604};
589605
590- static const SchemaQuery Query_for_list_of_views = {
591- .catname = "pg_catalog.pg_class c" ,
592- .selcondition = "c.relkind IN (" CppAsString2 (RELKIND_VIEW ) ")" ,
593- .viscondition = "pg_catalog.pg_table_is_visible(c.oid)" ,
594- .namespace = "c.relnamespace" ,
595- .result = "pg_catalog.quote_ident(c.relname)" ,
596- };
606+ /* Relations supporting CLUSTER are currently same as those supporting VACUUM */
607+ #define Query_for_list_of_clusterables Query_for_list_of_vacuumables
597608
598- static const SchemaQuery Query_for_list_of_matviews = {
599- .catname = "pg_catalog.pg_class c" ,
600- .selcondition = "c.relkind IN (" CppAsString2 ( RELKIND_MATVIEW ) ") " ,
601- .viscondition = "pg_catalog.pg_table_is_visible(c.oid)" ,
602- .namespace = "c.relnamespace " ,
603- .result = "pg_catalog.quote_ident(c.relname )" ,
609+ static const SchemaQuery Query_for_list_of_constraints_with_schema = {
610+ .catname = "pg_catalog.pg_constraint c" ,
611+ .selcondition = "c.conrelid <> 0 " ,
612+ .viscondition = "true" , /* there is no pg_constraint_is_visible */
613+ .namespace = "c.connamespace " ,
614+ .result = "pg_catalog.quote_ident(c.conname )" ,
604615};
605616
606617static const SchemaQuery Query_for_list_of_statistics = {
@@ -2169,9 +2180,9 @@ psql_completion(const char *text, int start, int end)
21692180 COMPLETE_WITH_CONST ("(" );
21702181/* CLUSTER */
21712182 else if (Matches1 ("CLUSTER" ))
2172- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tm , "UNION SELECT 'VERBOSE'" );
2183+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_clusterables , "UNION SELECT 'VERBOSE'" );
21732184 else if (Matches2 ("CLUSTER" , "VERBOSE" ))
2174- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tm , NULL );
2185+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_clusterables , NULL );
21752186 /* If we have CLUSTER <sth>, then add "USING" */
21762187 else if (Matches2 ("CLUSTER" , MatchAnyExcept ("VERBOSE|ON" )))
21772188 COMPLETE_WITH_CONST ("USING" );
@@ -2326,11 +2337,11 @@ psql_completion(const char *text, int start, int end)
23262337
23272338 /*
23282339 * Complete ... INDEX|CONCURRENTLY [<name>] ON with a list of relations
2329- * that can indexes can be created on
2340+ * that indexes can be created on
23302341 */
23312342 else if (TailMatches3 ("INDEX|CONCURRENTLY" , MatchAny , "ON" ) ||
23322343 TailMatches2 ("INDEX|CONCURRENTLY" , "ON" ))
2333- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tpm , NULL );
2344+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_indexables , NULL );
23342345
23352346 /*
23362347 * Complete CREATE|UNIQUE INDEX CONCURRENTLY with "ON" and existing
@@ -2903,8 +2914,7 @@ psql_completion(const char *text, int start, int end)
29032914 }
29042915
29052916 /*
2906- * Complete GRANT/REVOKE <sth> ON with a list of tables, views, and
2907- * sequences.
2917+ * Complete GRANT/REVOKE <sth> ON with a list of appropriate relations.
29082918 *
29092919 * Keywords like DATABASE, FUNCTION, LANGUAGE and SCHEMA added to query
29102920 * result via UNION; seems to work intuitively.
@@ -2922,7 +2932,7 @@ psql_completion(const char *text, int start, int end)
29222932 if (HeadMatches3 ("ALTER" , "DEFAULT" , "PRIVILEGES" ))
29232933 COMPLETE_WITH_LIST7 ("TABLES" , "SEQUENCES" , "FUNCTIONS" , "PROCEDURES" , "ROUTINES" , "TYPES" , "SCHEMAS" );
29242934 else
2925- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tsvmf ,
2935+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_grantables ,
29262936 " UNION SELECT 'ALL FUNCTIONS IN SCHEMA'"
29272937 " UNION SELECT 'ALL PROCEDURES IN SCHEMA'"
29282938 " UNION SELECT 'ALL ROUTINES IN SCHEMA'"
@@ -2977,7 +2987,7 @@ psql_completion(const char *text, int start, int end)
29772987 else if (TailMatches1 ("SEQUENCE" ))
29782988 COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_sequences , NULL );
29792989 else if (TailMatches1 ("TABLE" ))
2980- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tsvmf , NULL );
2990+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_grantables , NULL );
29812991 else if (TailMatches1 ("TABLESPACE" ))
29822992 COMPLETE_WITH_QUERY (Query_for_list_of_tablespaces );
29832993 else if (TailMatches1 ("TYPE" ))
@@ -3180,7 +3190,7 @@ psql_completion(const char *text, int start, int end)
31803190 else if (Matches1 ("REINDEX" ))
31813191 COMPLETE_WITH_LIST5 ("TABLE" , "INDEX" , "SYSTEM" , "SCHEMA" , "DATABASE" );
31823192 else if (Matches2 ("REINDEX" , "TABLE" ))
3183- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tm , NULL );
3193+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_indexables , NULL );
31843194 else if (Matches2 ("REINDEX" , "INDEX" ))
31853195 COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_indexes , NULL );
31863196 else if (Matches2 ("REINDEX" , "SCHEMA" ))
@@ -3327,7 +3337,7 @@ psql_completion(const char *text, int start, int end)
33273337
33283338/* TABLE, but not TABLE embedded in other commands */
33293339 else if (Matches1 ("TABLE" ))
3330- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tsvmf , NULL );
3340+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_selectables , NULL );
33313341
33323342/* TABLESAMPLE */
33333343 else if (TailMatches1 ("TABLESAMPLE" ))
@@ -3377,29 +3387,29 @@ psql_completion(const char *text, int start, int end)
33773387 * VACUUM [ FULL | FREEZE ] [ VERBOSE ] ANALYZE [ table [ (column [, ...] ) ] ]
33783388 */
33793389 else if (Matches1 ("VACUUM" ))
3380- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tm ,
3390+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_vacuumables ,
33813391 " UNION SELECT 'FULL'"
33823392 " UNION SELECT 'FREEZE'"
33833393 " UNION SELECT 'ANALYZE'"
33843394 " UNION SELECT 'VERBOSE'" );
33853395 else if (Matches2 ("VACUUM" , "FULL|FREEZE" ))
3386- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tm ,
3396+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_vacuumables ,
33873397 " UNION SELECT 'ANALYZE'"
33883398 " UNION SELECT 'VERBOSE'" );
33893399 else if (Matches3 ("VACUUM" , "FULL|FREEZE" , "ANALYZE" ))
3390- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tm ,
3400+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_vacuumables ,
33913401 " UNION SELECT 'VERBOSE'" );
33923402 else if (Matches3 ("VACUUM" , "FULL|FREEZE" , "VERBOSE" ))
3393- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tm ,
3403+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_vacuumables ,
33943404 " UNION SELECT 'ANALYZE'" );
33953405 else if (Matches2 ("VACUUM" , "VERBOSE" ))
3396- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tm ,
3406+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_vacuumables ,
33973407 " UNION SELECT 'ANALYZE'" );
33983408 else if (Matches2 ("VACUUM" , "ANALYZE" ))
3399- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tm ,
3409+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_vacuumables ,
34003410 " UNION SELECT 'VERBOSE'" );
34013411 else if (HeadMatches1 ("VACUUM" ))
3402- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tm , NULL );
3412+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_vacuumables , NULL );
34033413
34043414/* WITH [RECURSIVE] */
34053415
@@ -3411,9 +3421,9 @@ psql_completion(const char *text, int start, int end)
34113421 COMPLETE_WITH_CONST ("RECURSIVE" );
34123422
34133423/* ANALYZE */
3414- /* Complete with list of tables */
3424+ /* Complete with list of appropriate relations */
34153425 else if (Matches1 ("ANALYZE" ))
3416- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tmf , NULL );
3426+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_analyzables , NULL );
34173427
34183428/* WHERE */
34193429 /* Simple case of the word before the where being the table name */
@@ -3423,11 +3433,11 @@ psql_completion(const char *text, int start, int end)
34233433/* ... FROM ... */
34243434/* TODO: also include SRF ? */
34253435 else if (TailMatches1 ("FROM" ) && !Matches3 ("COPY|\\copy" , MatchAny , "FROM" ))
3426- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tsvmf , NULL );
3436+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_selectables , NULL );
34273437
34283438/* ... JOIN ... */
34293439 else if (TailMatches1 ("JOIN" ))
3430- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tsvmf , NULL );
3440+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_selectables , NULL );
34313441
34323442/* Backslash commands */
34333443/* TODO: \dc \dd \dl */
@@ -3477,7 +3487,7 @@ psql_completion(const char *text, int start, int end)
34773487 else if (TailMatchesCS1 ("\\dn*" ))
34783488 COMPLETE_WITH_QUERY (Query_for_list_of_schemas );
34793489 else if (TailMatchesCS1 ("\\dp" ) || TailMatchesCS1 ("\\z" ))
3480- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tsvmf , NULL );
3490+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_grantables , NULL );
34813491 else if (TailMatchesCS1 ("\\ds*" ))
34823492 COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_sequences , NULL );
34833493 else if (TailMatchesCS1 ("\\dt*" ))
0 commit comments