Improve search_path tab completion. search_path_completion
authorBernd Helmle <[email protected]>
Tue, 27 Aug 2013 21:54:31 +0000 (23:54 +0200)
committerBernd Helmle <[email protected]>
Tue, 27 Aug 2013 21:54:31 +0000 (23:54 +0200)
Only suggest namespace names the current role has sufficient
privileges on to use.

src/bin/psql/tab-complete.c

index 65d961089233f1615092ca28c990b563516bfb6a..3b6498671c5d7ec422bb05764de742eb4c68d736 100644 (file)
@@ -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
                {