Skip to content

Commit 1a51180

Browse files
committed
Improve tab-completion for DROP POLICY
Backpatch to 9.5. Author: Pavel Stěhule
1 parent f8d67ca commit 1a51180

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/bin/psql/tab-complete.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,19 @@ static const SchemaQuery Query_for_list_of_matviews = {
742742
" FROM pg_catalog.pg_tablesample_method "\
743743
" WHERE substring(pg_catalog.quote_ident(tsmname),1,%d)='%s'"
744744

745+
#define Query_for_list_of_policies \
746+
" SELECT pg_catalog.quote_ident(polname) "\
747+
" FROM pg_catalog.pg_policy " \
748+
" WHERE substring(pg_catalog.quote_ident(polname),1,%d)='%s'"
749+
750+
#define Query_for_list_of_tables_for_policy \
751+
"SELECT pg_catalog.quote_ident(relname) "\
752+
" FROM pg_catalog.pg_class"\
753+
" WHERE (%d = pg_catalog.length('%s'))"\
754+
" AND oid IN "\
755+
" (SELECT polrelid FROM pg_catalog.pg_policy "\
756+
" WHERE pg_catalog.quote_ident(polname)='%s')"
757+
745758
/*
746759
* This is a list of all "things" in Pgsql, which can show up after CREATE or
747760
* DROP; and there is also a query to get a list of them.
@@ -2891,15 +2904,26 @@ psql_completion(const char *text, int start, int end)
28912904
COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
28922905
}
28932906

2907+
/* DROP POLICY <name> */
2908+
else if (pg_strcasecmp(prev2_wd, "DROP") == 0 &&
2909+
pg_strcasecmp(prev_wd, "POLICY") == 0)
2910+
{
2911+
COMPLETE_WITH_QUERY(Query_for_list_of_policies);
2912+
}
28942913
/* DROP POLICY <name> ON */
28952914
else if (pg_strcasecmp(prev3_wd, "DROP") == 0 &&
28962915
pg_strcasecmp(prev2_wd, "POLICY") == 0)
2916+
{
28972917
COMPLETE_WITH_CONST("ON");
2918+
}
28982919
/* DROP POLICY <name> ON <table> */
28992920
else if (pg_strcasecmp(prev4_wd, "DROP") == 0 &&
29002921
pg_strcasecmp(prev3_wd, "POLICY") == 0 &&
29012922
pg_strcasecmp(prev_wd, "ON") == 0)
2902-
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
2923+
{
2924+
completion_info_charp = prev2_wd;
2925+
COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_policy);
2926+
}
29032927

29042928
/* DROP RULE */
29052929
else if (pg_strcasecmp(prev3_wd, "DROP") == 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