aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2015-07-20 15:37:17 +0200
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2015-07-20 15:37:17 +0200
commit1a5118008003b3c42f5cbb37980dabdb6a718e6f (patch)
tree22e13f1b35f5eca2afae4943ee029a015df31fc1 /src
parentf8d67ca8d4cbbbd6c6b3319d531089880d332534 (diff)
downloadpostgresql-1a5118008003b3c42f5cbb37980dabdb6a718e6f.tar.gz
postgresql-1a5118008003b3c42f5cbb37980dabdb6a718e6f.zip
Improve tab-completion for DROP POLICY
Backpatch to 9.5. Author: Pavel Stěhule
Diffstat (limited to 'src')
-rw-r--r--src/bin/psql/tab-complete.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 0683548940e..9596af6a7b3 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -742,6 +742,19 @@ static const SchemaQuery Query_for_list_of_matviews = {
" FROM pg_catalog.pg_tablesample_method "\
" WHERE substring(pg_catalog.quote_ident(tsmname),1,%d)='%s'"
+#define Query_for_list_of_policies \
+" SELECT pg_catalog.quote_ident(polname) "\
+" FROM pg_catalog.pg_policy " \
+" WHERE substring(pg_catalog.quote_ident(polname),1,%d)='%s'"
+
+#define Query_for_list_of_tables_for_policy \
+"SELECT pg_catalog.quote_ident(relname) "\
+" FROM pg_catalog.pg_class"\
+" WHERE (%d = pg_catalog.length('%s'))"\
+" AND oid IN "\
+" (SELECT polrelid FROM pg_catalog.pg_policy "\
+" WHERE pg_catalog.quote_ident(polname)='%s')"
+
/*
* This is a list of all "things" in Pgsql, which can show up after CREATE or
* 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)
COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
}
+ /* DROP POLICY <name> */
+ else if (pg_strcasecmp(prev2_wd, "DROP") == 0 &&
+ pg_strcasecmp(prev_wd, "POLICY") == 0)
+ {
+ COMPLETE_WITH_QUERY(Query_for_list_of_policies);
+ }
/* DROP POLICY <name> ON */
else if (pg_strcasecmp(prev3_wd, "DROP") == 0 &&
pg_strcasecmp(prev2_wd, "POLICY") == 0)
+ {
COMPLETE_WITH_CONST("ON");
+ }
/* DROP POLICY <name> ON <table> */
else if (pg_strcasecmp(prev4_wd, "DROP") == 0 &&
pg_strcasecmp(prev3_wd, "POLICY") == 0 &&
pg_strcasecmp(prev_wd, "ON") == 0)
- COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
+ {
+ completion_info_charp = prev2_wd;
+ COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_policy);
+ }
/* DROP RULE */
else if (pg_strcasecmp(prev3_wd, "DROP") == 0 &&