Tab-comletion for RLS
Hi all,
I found some lacks of tab-completion for RLS in 9.5.
* ALTER POLICY [TAB]
I expected to appear the list of policy name, but nothing is appeared.
* ALTER POLICY hoge_policy ON [TAB]
I expected to appear the list of table name related to specified policy,
but all table names are appeared.
* ALTER POLICY ... ON ... TO [TAB]
I expected to appear { role_name | PUBLIC | CURRENT_USER | SESSION_USER },
but only role_name and PUBLIC are appeared.
Same problem is exists in
"
CREATE POLICY ... ON ... TO [TAB]
"
.
#1 and #2 problems are exist in 9.5 or later, but #3 is exist in only 9.5
because it's unintentionally fixed by
2f8880704a697312d8d10ab3a2ad7ffe4b5e3dfd commit.
I think we should apply the necessary part of this commit for 9.5 as well,
though?
Attached patches are:
* 000_fix_tab_completion_rls.patch
fixes #1, #2 problem, and is for master branch and REL9_5_STABLE.
* 001_fix_tab_completion_rls_for_95.patch
fixes #3 problem, and is for only REL9_5_STABLE.
Regards,
--
Masahiko Sawada
Attachments:
000_fix_tab_completion_rls.patchapplication/octet-stream; name=000_fix_tab_completion_rls.patchDownload
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index b2d627f..a1ccc65 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -1424,6 +1424,10 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_LIST(list_ALTERMATVIEW);
}
+ /* ALTER POLICY <name> */
+ else if (pg_strcasecmp(prev2_wd, "ALTER") == 0 &&
+ pg_strcasecmp(prev_wd, "POLICY") == 0)
+ COMPLETE_WITH_QUERY(Query_for_list_of_policies);
/* ALTER POLICY <name> ON */
else if (pg_strcasecmp(prev3_wd, "ALTER") == 0 &&
pg_strcasecmp(prev2_wd, "POLICY") == 0)
@@ -1432,7 +1436,10 @@ psql_completion(const char *text, int start, int end)
else if (pg_strcasecmp(prev4_wd, "ALTER") == 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);
+ }
/* ALTER POLICY <name> ON <table> - show options */
else if (pg_strcasecmp(prev5_wd, "ALTER") == 0 &&
pg_strcasecmp(prev4_wd, "POLICY") == 0 &&
001_fix_tab_completion_rls_for_95.patchapplication/octet-stream; name=001_fix_tab_completion_rls_for_95.patchDownload
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index a1ccc65..f9b461d 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -576,7 +576,9 @@ static const SchemaQuery Query_for_list_of_matviews = {
" SELECT pg_catalog.quote_ident(rolname) "\
" FROM pg_catalog.pg_roles "\
" WHERE substring(pg_catalog.quote_ident(rolname),1,%d)='%s'"\
-" UNION ALL SELECT 'PUBLIC'"
+" UNION ALL SELECT 'PUBLIC'"\
+" UNION ALL SELECT 'CURRENT_USER'"\
+" UNION ALL SELECT 'SESSION_USER'"\
/* the silly-looking length condition is just to eat up the current word */
#define Query_for_table_owning_index \
@@ -3040,6 +3042,11 @@ psql_completion(const char *text, int start, int end)
pg_strcasecmp(prev_wd, "TABLE") == 0)
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_foreign_tables, NULL);
+/* FOREIGN SERVER */
+ else if (pg_strcasecmp(prev2_wd, "FOREIGN") == 0 &&
+ pg_strcasecmp(prev_wd, "SERVER") == 0)
+ COMPLETE_WITH_QUERY(Query_for_list_of_servers);
+
/* GRANT && REVOKE */
/* Complete GRANT/REVOKE with a list of roles and privileges */
else if (pg_strcasecmp(prev_wd, "GRANT") == 0 ||
On Tue, Dec 8, 2015 at 8:32 AM, Masahiko Sawada <sawada.mshk@gmail.com> wrote:
I found some lacks of tab-completion for RLS in 9.5.
* ALTER POLICY [TAB]
I expected to appear the list of policy name, but nothing is appeared.* ALTER POLICY hoge_policy ON [TAB]
I expected to appear the list of table name related to specified policy, but
all table names are appeared.* ALTER POLICY ... ON ... TO [TAB]
I expected to appear { role_name | PUBLIC | CURRENT_USER | SESSION_USER },
but only role_name and PUBLIC are appeared.
Same problem is exists in
"
CREATE POLICY ... ON ... TO [TAB]
"
.#1 and #2 problems are exist in 9.5 or later, but #3 is exist in only 9.5
because it's unintentionally fixed by
2f8880704a697312d8d10ab3a2ad7ffe4b5e3dfd commit.
I think we should apply the necessary part of this commit for 9.5 as well,
though?Attached patches are:
* 000_fix_tab_completion_rls.patch
fixes #1, #2 problem, and is for master branch and REL9_5_STABLE.
* 001_fix_tab_completion_rls_for_95.patch
fixes #3 problem, and is for only REL9_5_STABLE.
I've committed 000 and back-patched it to 9.5. I'm not quite sure
what to do about 001; maybe it's better to back-port the whole commit
rather than just bits of it.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Thu, Dec 10, 2015 at 11:07 PM, Robert Haas <robertmhaas@gmail.com> wrote:
On Tue, Dec 8, 2015 at 8:32 AM, Masahiko Sawada <sawada.mshk@gmail.com> wrote:
I found some lacks of tab-completion for RLS in 9.5.
* ALTER POLICY [TAB]
I expected to appear the list of policy name, but nothing is appeared.* ALTER POLICY hoge_policy ON [TAB]
I expected to appear the list of table name related to specified policy, but
all table names are appeared.* ALTER POLICY ... ON ... TO [TAB]
I expected to appear { role_name | PUBLIC | CURRENT_USER | SESSION_USER },
but only role_name and PUBLIC are appeared.
Same problem is exists in
"
CREATE POLICY ... ON ... TO [TAB]
"
.#1 and #2 problems are exist in 9.5 or later, but #3 is exist in only 9.5
because it's unintentionally fixed by
2f8880704a697312d8d10ab3a2ad7ffe4b5e3dfd commit.
I think we should apply the necessary part of this commit for 9.5 as well,
though?Attached patches are:
* 000_fix_tab_completion_rls.patch
fixes #1, #2 problem, and is for master branch and REL9_5_STABLE.
* 001_fix_tab_completion_rls_for_95.patch
fixes #3 problem, and is for only REL9_5_STABLE.I've committed 000 and back-patched it to 9.5. I'm not quite sure
what to do about 001; maybe it's better to back-port the whole commit
rather than just bits of it.
Yes, I agree with back-port the whole commit.
Regards,
--
Masahiko Sawada
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Fri, Dec 11, 2015 at 11:56 AM, Masahiko Sawada <sawada.mshk@gmail.com> wrote:
On Thu, Dec 10, 2015 at 11:07 PM, Robert Haas <robertmhaas@gmail.com> wrote:
On Tue, Dec 8, 2015 at 8:32 AM, Masahiko Sawada <sawada.mshk@gmail.com> wrote:
I found some lacks of tab-completion for RLS in 9.5.
* ALTER POLICY [TAB]
I expected to appear the list of policy name, but nothing is appeared.* ALTER POLICY hoge_policy ON [TAB]
I expected to appear the list of table name related to specified policy, but
all table names are appeared.* ALTER POLICY ... ON ... TO [TAB]
I expected to appear { role_name | PUBLIC | CURRENT_USER | SESSION_USER },
but only role_name and PUBLIC are appeared.
Same problem is exists in
"
CREATE POLICY ... ON ... TO [TAB]
"
.#1 and #2 problems are exist in 9.5 or later, but #3 is exist in only 9.5
because it's unintentionally fixed by
2f8880704a697312d8d10ab3a2ad7ffe4b5e3dfd commit.
I think we should apply the necessary part of this commit for 9.5 as well,
though?Attached patches are:
* 000_fix_tab_completion_rls.patch
fixes #1, #2 problem, and is for master branch and REL9_5_STABLE.
* 001_fix_tab_completion_rls_for_95.patch
fixes #3 problem, and is for only REL9_5_STABLE.I've committed 000 and back-patched it to 9.5. I'm not quite sure
what to do about 001; maybe it's better to back-port the whole commit
rather than just bits of it.Yes, I agree with back-port the whole commit.
On further review, this doesn't really seem like a sufficiently
critical issue to justify back-porting that commit. I won't make a
stink if some other committer wants to push that commit into 9.5, but
I don't want to do it myself and then be left holding the bag if it
breaks something. We're generally pretty lenient about pushing tab
completion patches into the tree even well after feature freeze, but
post-rc1 is a little more than I want to be on the hook for. This is
clearly not a bug; it's just a feature that you'd like to have. And
9.6 will have it.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers