summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernd Helmle2013-08-27 21:54:31 +0000
committerBernd Helmle2013-08-27 21:54:31 +0000
commit03fd00cd190e8b529efeec1a1bb038454fb0b05f (patch)
tree63dbf1bc8db810e0d811991b8ba09ff68a04273d
parenta46b35dbc36df38d42c8b8538aeee724f47030d1 (diff)
Improve search_path tab completion.search_path_completion
Only suggest namespace names the current role has sufficient privileges on to use.
-rw-r--r--src/bin/psql/tab-complete.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 65d9610892..3b6498671c 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -576,6 +576,12 @@ static const SchemaQuery Query_for_list_of_matviews = {
"SELECT pg_catalog.quote_ident(nspname) FROM pg_catalog.pg_namespace "\
" WHERE substring(pg_catalog.quote_ident(nspname),1,%d)='%s'"
+#define Query_for_list_of_schemas_with_privs \
+"SELECT pg_catalog.quote_ident(nspname) FROM pg_catalog.pg_namespace "\
+" WHERE substring(pg_catalog.quote_ident(nspname),1,%d)='%s'"\
+" AND (has_schema_privilege(current_role::name, oid, 'USAGE'::text)"\
+" OR has_schema_privilege(current_role::name, oid, 'CREATE'::text))"
+
#define Query_for_list_of_set_vars \
"SELECT name FROM "\
" (SELECT pg_catalog.lower(name) AS name FROM pg_catalog.pg_settings "\
@@ -3123,7 +3129,7 @@ psql_completion(char *text, int start, int end)
}
else if (pg_strcasecmp(prev2_wd, "search_path") == 0)
{
- COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
+ COMPLETE_WITH_QUERY(Query_for_list_of_schemas_with_privs);
}
else
{