pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedGRANT USAGE ON SEQUENCE missing from psql command completion
19+ messages / 5 participants
[nested] [flat]
* GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-08-20 02:54 Josh Berkus <josh@agliodbs.com>
0 siblings, 1 reply; 19+ messages in thread
From: Josh Berkus @ 2015-08-20 02:54 UTC (permalink / raw)
To: pgsql-bugs
Versions tested: 9.4.4, 9.5a2
Steps to reproduce:
1. psql to a database with sequences
2. type "grant usage on " and hit tab
3. "sequence" does not appear
4. type "grant usage on sequence " and hit tab
5. completes with word "to" which is incorrect.
--
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-08-20 03:10 Thomas Munro <thomas.munro@enterprisedb.com>
parent: Josh Berkus <josh@agliodbs.com>
0 siblings, 2 replies; 19+ messages in thread
From: Thomas Munro @ 2015-08-20 03:10 UTC (permalink / raw)
To: Josh Berkus <josh@agliodbs.com>; +Cc: pgsql-bugs
On Thu, Aug 20, 2015 at 2:54 PM, Josh Berkus <josh@agliodbs.com> wrote:
> Versions tested: 9.4.4, 9.5a2
>
> Steps to reproduce:
>
> 1. psql to a database with sequences
>
> 2. type "grant usage on " and hit tab
>
> 3. "sequence" does not appear
>
> 4. type "grant usage on sequence " and hit tab
>
> 5. completes with word "to" which is incorrect.
Here's a patch for that.
--
Thomas Munro
http://www.enterprisedb.com
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
tab-complete-grant-sequence.patch (application/octet-stream, 1.0K) download
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 816deda..e6d2de9 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3140,6 +3140,7 @@ psql_completion(const char *text, int start, int end)
" UNION SELECT 'LANGUAGE'"
" UNION SELECT 'LARGE OBJECT'"
" UNION SELECT 'SCHEMA'"
+ " UNION SELECT 'SEQUENCE'"
" UNION SELECT 'TABLESPACE'"
" UNION SELECT 'TYPE'");
else if ((pg_strcasecmp(prev4_wd, "GRANT") == 0 ||
@@ -3168,6 +3169,8 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_QUERY(Query_for_list_of_languages);
else if (pg_strcasecmp(prev_wd, "SCHEMA") == 0)
COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
+ else if (pg_strcasecmp(prev_wd, "SEQUENCE") == 0)
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_sequences, NULL);
else if (pg_strcasecmp(prev_wd, "TABLESPACE") == 0)
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
else if (pg_strcasecmp(prev_wd, "TYPE") == 0)
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-08-20 03:20 Michael Paquier <michael.paquier@gmail.com>
parent: Thomas Munro <thomas.munro@enterprisedb.com>
1 sibling, 1 reply; 19+ messages in thread
From: Michael Paquier @ 2015-08-20 03:20 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: Josh Berkus <josh@agliodbs.com>; pgsql-bugs
On Thu, Aug 20, 2015 at 12:10 PM, Thomas Munro <
thomas.munro@enterprisedb.com> wrote:
> On Thu, Aug 20, 2015 at 2:54 PM, Josh Berkus <josh@agliodbs.com> wrote:
> > Versions tested: 9.4.4, 9.5a2
> >
> > Steps to reproduce:
> >
> > 1. psql to a database with sequences
> >
> > 2. type "grant usage on " and hit tab
> >
> > 3. "sequence" does not appear
> >
> > 4. type "grant usage on sequence " and hit tab
> >
> > 5. completes with word "to" which is incorrect.
>
> Here's a patch for that.
>
Don't we want to add TABLE as well? That's the default with just ON but it
seems useful to me to show up only a list of tables without all those
keywords.
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
20150820_tab_complete_grant.patch (application/x-patch, 1.2K) download
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 62cb721..3650028 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3139,6 +3139,8 @@ psql_completion(const char *text, int start, int end)
" UNION SELECT 'LANGUAGE'"
" UNION SELECT 'LARGE OBJECT'"
" UNION SELECT 'SCHEMA'"
+ " UNION SELECT 'SEQUENCE'"
+ " UNION SELECT 'TABLE'"
" UNION SELECT 'TABLESPACE'"
" UNION SELECT 'TYPE'");
else if ((pg_strcasecmp(prev4_wd, "GRANT") == 0 ||
@@ -3167,6 +3169,10 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_QUERY(Query_for_list_of_languages);
else if (pg_strcasecmp(prev_wd, "SCHEMA") == 0)
COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
+ else if (pg_strcasecmp(prev_wd, "SEQUENCE") == 0)
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_sequences, NULL);
+ else if (pg_strcasecmp(prev_wd, "TABLE") == 0)
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
else if (pg_strcasecmp(prev_wd, "TABLESPACE") == 0)
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
else if (pg_strcasecmp(prev_wd, "TYPE") == 0)
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-08-20 03:22 Josh Berkus <josh@agliodbs.com>
parent: Thomas Munro <thomas.munro@enterprisedb.com>
1 sibling, 0 replies; 19+ messages in thread
From: Josh Berkus @ 2015-08-20 03:22 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: pgsql-bugs
On 08/19/2015 08:10 PM, Thomas Munro wrote:
> On Thu, Aug 20, 2015 at 2:54 PM, Josh Berkus <josh@agliodbs.com> wrote:
>> Versions tested: 9.4.4, 9.5a2
>>
>> Steps to reproduce:
>>
>> 1. psql to a database with sequences
>>
>> 2. type "grant usage on " and hit tab
>>
>> 3. "sequence" does not appear
>>
>> 4. type "grant usage on sequence " and hit tab
>>
>> 5. completes with word "to" which is incorrect.
>
> Here's a patch for that.
>
Passes my ad-hoc tests, including non-default schema.
--
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-09-01 02:42 Thomas Munro <thomas.munro@enterprisedb.com>
parent: Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 19+ messages in thread
From: Thomas Munro @ 2015-09-01 02:42 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Josh Berkus <josh@agliodbs.com>; pgsql-bugs
On Thu, Aug 20, 2015 at 3:20 PM, Michael Paquier <michael.paquier@gmail.com>
wrote:
>
> On Thu, Aug 20, 2015 at 12:10 PM, Thomas Munro <
> thomas.munro@enterprisedb.com> wrote:
>
>> On Thu, Aug 20, 2015 at 2:54 PM, Josh Berkus <josh@agliodbs.com> wrote:
>> > Versions tested: 9.4.4, 9.5a2
>> >
>> > Steps to reproduce:
>> >
>> > 1. psql to a database with sequences
>> >
>> > 2. type "grant usage on " and hit tab
>> >
>> > 3. "sequence" does not appear
>> >
>> > 4. type "grant usage on sequence " and hit tab
>> >
>> > 5. completes with word "to" which is incorrect.
>>
>> Here's a patch for that.
>>
>
> Don't we want to add TABLE as well? That's the default with just ON but it
> seems useful to me to show up only a list of tables without all those
> keywords.
>
Agreed. I noticed a couple more things:
1. GRANT/REVOKE * ON DATABASE/SEQUENCE/TABLE/... * TO/FROM <tab> doesn't
suggest roles, as it should.
2. GRANT/REVOKE * ON ALL FUNCTIONS/SEQUENCES/TABLES IN SCHEMA ... isn't
supported and might as well be.
New patch attached to address those. I added this to the open commitfest.
--
Thomas Munro
http://www.enterprisedb.com
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
tab-complete-grant.patch (application/octet-stream, 5.9K) download
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 816deda..77580ba 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -888,7 +888,7 @@ psql_completion(const char *text, int start, int end)
char **matches = NULL;
/* This array will contain some scannage of the input line. */
- char *previous_words[6];
+ char *previous_words[9];
/* For compactness, we use these macros to reference previous_words[]. */
#define prev_wd (previous_words[0])
@@ -897,6 +897,9 @@ psql_completion(const char *text, int start, int end)
#define prev4_wd (previous_words[3])
#define prev5_wd (previous_words[4])
#define prev6_wd (previous_words[5])
+#define prev7_wd (previous_words[6])
+#define prev8_wd (previous_words[7])
+#define prev9_wd (previous_words[8])
static const char *const sql_commands[] = {
"ABORT", "ALTER", "ANALYZE", "BEGIN", "CHECKPOINT", "CLOSE", "CLUSTER",
@@ -3132,6 +3135,9 @@ psql_completion(const char *text, int start, int end)
pg_strcasecmp(prev3_wd, "REVOKE") == 0) &&
pg_strcasecmp(prev_wd, "ON") == 0)
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tsvmf,
+ " UNION SELECT 'ALL FUNCTIONS IN SCHEMA'"
+ " UNION SELECT 'ALL SEQUENCES IN SCHEMA'"
+ " UNION SELECT 'ALL TABLES IN SCHEMA'"
" UNION SELECT 'DATABASE'"
" UNION SELECT 'DOMAIN'"
" UNION SELECT 'FOREIGN DATA WRAPPER'"
@@ -3140,11 +3146,24 @@ psql_completion(const char *text, int start, int end)
" UNION SELECT 'LANGUAGE'"
" UNION SELECT 'LARGE OBJECT'"
" UNION SELECT 'SCHEMA'"
+ " UNION SELECT 'SEQUENCE'"
+ " UNION SELECT 'TABLE'"
" UNION SELECT 'TABLESPACE'"
" UNION SELECT 'TYPE'");
else if ((pg_strcasecmp(prev4_wd, "GRANT") == 0 ||
pg_strcasecmp(prev4_wd, "REVOKE") == 0) &&
pg_strcasecmp(prev2_wd, "ON") == 0 &&
+ pg_strcasecmp(prev_wd, "ALL") == 0)
+ {
+ static const char *const list_privilege_all[] =
+ {"FUNCTIONS IN SCHEMA", "SEQUENCES IN SCHEMA", "TABLES IN SCHEMA", NULL};
+
+ COMPLETE_WITH_LIST(list_privilege_all);
+ }
+
+ else if ((pg_strcasecmp(prev4_wd, "GRANT") == 0 ||
+ pg_strcasecmp(prev4_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev2_wd, "ON") == 0 &&
pg_strcasecmp(prev_wd, "FOREIGN") == 0)
{
static const char *const list_privilege_foreign[] =
@@ -3153,7 +3172,12 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_LIST(list_privilege_foreign);
}
- /* Complete "GRANT/REVOKE * ON * " with "TO/FROM" */
+ /*
+ * Complete "GRANT/REMOVE * ON DATABASE/DOMAIN/..." with a list of
+ * appropriate objects.
+ *
+ * Complete "GRANT/REVOKE * ON * " with "TO/FROM".
+ */
else if ((pg_strcasecmp(prev4_wd, "GRANT") == 0 ||
pg_strcasecmp(prev4_wd, "REVOKE") == 0) &&
pg_strcasecmp(prev2_wd, "ON") == 0)
@@ -3168,6 +3192,10 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_QUERY(Query_for_list_of_languages);
else if (pg_strcasecmp(prev_wd, "SCHEMA") == 0)
COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
+ else if (pg_strcasecmp(prev_wd, "SEQUENCE") == 0)
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_sequences, NULL);
+ else if (pg_strcasecmp(prev_wd, "TABLE") == 0)
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
else if (pg_strcasecmp(prev_wd, "TABLESPACE") == 0)
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
else if (pg_strcasecmp(prev_wd, "TYPE") == 0)
@@ -3178,20 +3206,50 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_CONST("FROM");
}
- /* Complete "GRANT/REVOKE * ON * TO/FROM" with username, GROUP, or PUBLIC */
- else if (pg_strcasecmp(prev5_wd, "GRANT") == 0 &&
+ /*
+ * Complete "GRANT/REVOKE * ON * TO/FROM" with username, GROUP, or PUBLIC.
+ *
+ * Complete "GRANT/REVOKE * ON * * TO/FROM" with username, GROUP, or
+ * PUBLIC.
+ *
+ * Complete "GRANT/REVOKE * ON ALL * IN SCHEMA * TO/FROM" with username,
+ * GROUP, or PUBLIC.
+ */
+ else if (((pg_strcasecmp(prev9_wd, "GRANT") == 0 || pg_strcasecmp(prev9_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev7_wd, "ON") == 0 &&
+ pg_strcasecmp(prev6_wd, "ALL") == 0 &&
+ pg_strcasecmp(prev4_wd, "IN") == 0 &&
+ pg_strcasecmp(prev3_wd, "SCHEMA") == 0 &&
+ (pg_strcasecmp(prev_wd, "TO") == 0 || pg_strcasecmp(prev_wd, "FROM") == 0)) ||
+ ((pg_strcasecmp(prev6_wd, "GRANT") == 0 || pg_strcasecmp(prev6_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev4_wd, "ON") == 0 &&
+ (pg_strcasecmp(prev_wd, "TO") == 0 || pg_strcasecmp(prev_wd, "FROM") == 0)) ||
+ ((pg_strcasecmp(prev5_wd, "GRANT") == 0 || pg_strcasecmp(prev5_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev3_wd, "ON") == 0 &&
+ (pg_strcasecmp(prev_wd, "TO") == 0 || pg_strcasecmp(prev_wd, "FROM") == 0)))
+ {
+ COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+ }
+
+ /* Complete "GRANT/REVOKE * ON * *" with TO or FROM */
+ else if ((pg_strcasecmp(prev5_wd, "GRANT") == 0 || pg_strcasecmp(prev5_wd, "REVOKE") == 0) &&
pg_strcasecmp(prev3_wd, "ON") == 0)
{
- if (pg_strcasecmp(prev_wd, "TO") == 0)
- COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
- else
+ if (pg_strcasecmp(prev5_wd, "GRANT") == 0)
COMPLETE_WITH_CONST("TO");
+ else
+ COMPLETE_WITH_CONST("FROM");
}
- else if (pg_strcasecmp(prev5_wd, "REVOKE") == 0 &&
- pg_strcasecmp(prev3_wd, "ON") == 0)
+
+ /* Complete "GRANT/REVOKE * ON ALL IN SCHEMA *" with TO or FROM */
+ else if ((pg_strcasecmp(prev8_wd, "GRANT") == 0 || pg_strcasecmp(prev8_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev6_wd, "ON") == 0 &&
+ pg_strcasecmp(prev5_wd, "ALL") == 0 &&
+ pg_strcasecmp(prev3_wd, "IN") == 0 &&
+ pg_strcasecmp(prev2_wd, "SCHEMA") == 0)
{
- if (pg_strcasecmp(prev_wd, "FROM") == 0)
- COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+ if (pg_strcasecmp(prev8_wd, "GRANT") == 0)
+ COMPLETE_WITH_CONST("TO");
else
COMPLETE_WITH_CONST("FROM");
}
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-09-01 04:24 Michael Paquier <michael.paquier@gmail.com>
parent: Thomas Munro <thomas.munro@enterprisedb.com>
0 siblings, 1 reply; 19+ messages in thread
From: Michael Paquier @ 2015-09-01 04:24 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: Josh Berkus <josh@agliodbs.com>; pgsql-bugs
On Tue, Sep 1, 2015 at 11:42 AM, Thomas Munro
<thomas.munro@enterprisedb.com> wrote:
> On Thu, Aug 20, 2015 at 3:20 PM, Michael Paquier <michael.paquier@gmail.com>
> wrote:
>>
>> On Thu, Aug 20, 2015 at 12:10 PM, Thomas Munro
>> <thomas.munro@enterprisedb.com> wrote:
>>>
>>> On Thu, Aug 20, 2015 at 2:54 PM, Josh Berkus <josh@agliodbs.com> wrote:
>>> > Versions tested: 9.4.4, 9.5a2
>>> >
>>> > Steps to reproduce:
>>> >
>>> > 1. psql to a database with sequences
>>> >
>>> > 2. type "grant usage on " and hit tab
>>> >
>>> > 3. "sequence" does not appear
>>> >
>>> > 4. type "grant usage on sequence " and hit tab
>>> >
>>> > 5. completes with word "to" which is incorrect.
>>>
>>> Here's a patch for that.
>>
>>
>> Don't we want to add TABLE as well? That's the default with just ON but it
>> seems useful to me to show up only a list of tables without all those
>> keywords.
>
>
> Agreed. I noticed a couple more things:
>
> 1. GRANT/REVOKE * ON DATABASE/SEQUENCE/TABLE/... * TO/FROM <tab> doesn't
> suggest roles, as it should.
> 2. GRANT/REVOKE * ON ALL FUNCTIONS/SEQUENCES/TABLES IN SCHEMA ... isn't
> supported and might as well be.
Agreed on both points.
> New patch attached to address those. I added this to the open commitfest.
Those are incorrect suggestions:
=# grant ALL on ALL sequences in schema public from
postgres PUBLIC
=# revoke ALL on ALL sequences in schema public to
postgres PUBLIC
And that's caused by this monster:
+ else if (((pg_strcasecmp(prev9_wd, "GRANT") == 0 ||
pg_strcasecmp(prev9_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev7_wd, "ON") == 0 &&
+ pg_strcasecmp(prev6_wd, "ALL") == 0 &&
+ pg_strcasecmp(prev4_wd, "IN") == 0 &&
+ pg_strcasecmp(prev3_wd, "SCHEMA") == 0 &&
+ (pg_strcasecmp(prev_wd, "TO") == 0 ||
pg_strcasecmp(prev_wd, "FROM") == 0)) ||
+ ((pg_strcasecmp(prev6_wd, "GRANT") == 0 ||
pg_strcasecmp(prev6_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev4_wd, "ON") == 0 &&
+ (pg_strcasecmp(prev_wd, "TO") == 0 ||
pg_strcasecmp(prev_wd, "FROM") == 0)) ||
+ ((pg_strcasecmp(prev5_wd, "GRANT") == 0 ||
pg_strcasecmp(prev5_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev3_wd, "ON") == 0 &&
+ (pg_strcasecmp(prev_wd, "TO") == 0 ||
pg_strcasecmp(prev_wd, "FROM") == 0)))
Could it be possible to simplify it a bit? You could either separate
it in two for REVOKE and GRANT or use an inner evaluation after
SCHEMA.
Regards,
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-09-01 13:15 Thomas Munro <thomas.munro@enterprisedb.com>
parent: Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 19+ messages in thread
From: Thomas Munro @ 2015-09-01 13:15 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Josh Berkus <josh@agliodbs.com>; pgsql-bugs
On Tue, Sep 1, 2015 at 4:24 PM, Michael Paquier <michael.paquier@gmail.com>
wrote:
> On Tue, Sep 1, 2015 at 11:42 AM, Thomas Munro
> <thomas.munro@enterprisedb.com> wrote:
> > On Thu, Aug 20, 2015 at 3:20 PM, Michael Paquier <
> michael.paquier@gmail.com>
> > wrote:
> >>
> >> On Thu, Aug 20, 2015 at 12:10 PM, Thomas Munro
> >> <thomas.munro@enterprisedb.com> wrote:
> >>>
> >>> On Thu, Aug 20, 2015 at 2:54 PM, Josh Berkus <josh@agliodbs.com>
> wrote:
> >>> > Versions tested: 9.4.4, 9.5a2
> >>> >
> >>> > Steps to reproduce:
> >>> >
> >>> > 1. psql to a database with sequences
> >>> >
> >>> > 2. type "grant usage on " and hit tab
> >>> >
> >>> > 3. "sequence" does not appear
> >>> >
> >>> > 4. type "grant usage on sequence " and hit tab
> >>> >
> >>> > 5. completes with word "to" which is incorrect.
> >>>
> >>> Here's a patch for that.
> >>
> >>
> >> Don't we want to add TABLE as well? That's the default with just ON but
> it
> >> seems useful to me to show up only a list of tables without all those
> >> keywords.
> >
> >
> > Agreed. I noticed a couple more things:
> >
> > 1. GRANT/REVOKE * ON DATABASE/SEQUENCE/TABLE/... * TO/FROM <tab> doesn't
> > suggest roles, as it should.
> > 2. GRANT/REVOKE * ON ALL FUNCTIONS/SEQUENCES/TABLES IN SCHEMA ... isn't
> > supported and might as well be.
>
> Agreed on both points.
>
> > New patch attached to address those. I added this to the open
> commitfest.
>
> Those are incorrect suggestions:
> =# grant ALL on ALL sequences in schema public from
> postgres PUBLIC
> =# revoke ALL on ALL sequences in schema public to
> postgres PUBLIC
>
> And that's caused by this monster:
> + else if (((pg_strcasecmp(prev9_wd, "GRANT") == 0 ||
> pg_strcasecmp(prev9_wd, "REVOKE") == 0) &&
> + pg_strcasecmp(prev7_wd, "ON") == 0 &&
> + pg_strcasecmp(prev6_wd, "ALL") == 0 &&
> + pg_strcasecmp(prev4_wd, "IN") == 0 &&
> + pg_strcasecmp(prev3_wd, "SCHEMA") == 0 &&
> + (pg_strcasecmp(prev_wd, "TO") == 0 ||
> pg_strcasecmp(prev_wd, "FROM") == 0)) ||
> + ((pg_strcasecmp(prev6_wd, "GRANT") == 0 ||
> pg_strcasecmp(prev6_wd, "REVOKE") == 0) &&
> + pg_strcasecmp(prev4_wd, "ON") == 0 &&
> + (pg_strcasecmp(prev_wd, "TO") == 0 ||
> pg_strcasecmp(prev_wd, "FROM") == 0)) ||
> + ((pg_strcasecmp(prev5_wd, "GRANT") == 0 ||
> pg_strcasecmp(prev5_wd, "REVOKE") == 0) &&
> + pg_strcasecmp(prev3_wd, "ON") == 0 &&
> + (pg_strcasecmp(prev_wd, "TO") == 0 ||
> pg_strcasecmp(prev_wd, "FROM") == 0)))
> Could it be possible to simplify it a bit? You could either separate
> it in two for REVOKE and GRANT or use an inner evaluation after
> SCHEMA.
Here is a version that splits that monster up into three small smaller
blocks, and makes sure that GRANT goes with TO and REVOKE goes with FROM
before completing with roles.
Unfortunately your first example "GRANT ... FROM <tab>" still gets
inappropriate completion because of the general FROM-matching branch with
comment /* ... FROM ... */ that comes near the end, but it didn't seem
sensible to start teaching the general FROM branch about avoiding this
specific invalid production when it's happy to complete "BANANA FROM <tab>".
--
Thomas Munro
http://www.enterprisedb.com
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
tab-complete-grant-v2.patch (application/octet-stream, 6.0K) download
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 816deda..69309f9 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -888,7 +888,7 @@ psql_completion(const char *text, int start, int end)
char **matches = NULL;
/* This array will contain some scannage of the input line. */
- char *previous_words[6];
+ char *previous_words[9];
/* For compactness, we use these macros to reference previous_words[]. */
#define prev_wd (previous_words[0])
@@ -897,6 +897,9 @@ psql_completion(const char *text, int start, int end)
#define prev4_wd (previous_words[3])
#define prev5_wd (previous_words[4])
#define prev6_wd (previous_words[5])
+#define prev7_wd (previous_words[6])
+#define prev8_wd (previous_words[7])
+#define prev9_wd (previous_words[8])
static const char *const sql_commands[] = {
"ABORT", "ALTER", "ANALYZE", "BEGIN", "CHECKPOINT", "CLOSE", "CLUSTER",
@@ -3132,6 +3135,9 @@ psql_completion(const char *text, int start, int end)
pg_strcasecmp(prev3_wd, "REVOKE") == 0) &&
pg_strcasecmp(prev_wd, "ON") == 0)
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tsvmf,
+ " UNION SELECT 'ALL FUNCTIONS IN SCHEMA'"
+ " UNION SELECT 'ALL SEQUENCES IN SCHEMA'"
+ " UNION SELECT 'ALL TABLES IN SCHEMA'"
" UNION SELECT 'DATABASE'"
" UNION SELECT 'DOMAIN'"
" UNION SELECT 'FOREIGN DATA WRAPPER'"
@@ -3140,11 +3146,24 @@ psql_completion(const char *text, int start, int end)
" UNION SELECT 'LANGUAGE'"
" UNION SELECT 'LARGE OBJECT'"
" UNION SELECT 'SCHEMA'"
+ " UNION SELECT 'SEQUENCE'"
+ " UNION SELECT 'TABLE'"
" UNION SELECT 'TABLESPACE'"
" UNION SELECT 'TYPE'");
else if ((pg_strcasecmp(prev4_wd, "GRANT") == 0 ||
pg_strcasecmp(prev4_wd, "REVOKE") == 0) &&
pg_strcasecmp(prev2_wd, "ON") == 0 &&
+ pg_strcasecmp(prev_wd, "ALL") == 0)
+ {
+ static const char *const list_privilege_all[] =
+ {"FUNCTIONS IN SCHEMA", "SEQUENCES IN SCHEMA", "TABLES IN SCHEMA", NULL};
+
+ COMPLETE_WITH_LIST(list_privilege_all);
+ }
+
+ else if ((pg_strcasecmp(prev4_wd, "GRANT") == 0 ||
+ pg_strcasecmp(prev4_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev2_wd, "ON") == 0 &&
pg_strcasecmp(prev_wd, "FOREIGN") == 0)
{
static const char *const list_privilege_foreign[] =
@@ -3153,7 +3172,12 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_LIST(list_privilege_foreign);
}
- /* Complete "GRANT/REVOKE * ON * " with "TO/FROM" */
+ /*
+ * Complete "GRANT/REMOVE * ON DATABASE/DOMAIN/..." with a list of
+ * appropriate objects.
+ *
+ * Complete "GRANT/REVOKE * ON * " with "TO/FROM".
+ */
else if ((pg_strcasecmp(prev4_wd, "GRANT") == 0 ||
pg_strcasecmp(prev4_wd, "REVOKE") == 0) &&
pg_strcasecmp(prev2_wd, "ON") == 0)
@@ -3168,6 +3192,10 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_QUERY(Query_for_list_of_languages);
else if (pg_strcasecmp(prev_wd, "SCHEMA") == 0)
COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
+ else if (pg_strcasecmp(prev_wd, "SEQUENCE") == 0)
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_sequences, NULL);
+ else if (pg_strcasecmp(prev_wd, "TABLE") == 0)
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
else if (pg_strcasecmp(prev_wd, "TABLESPACE") == 0)
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
else if (pg_strcasecmp(prev_wd, "TYPE") == 0)
@@ -3178,20 +3206,54 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_CONST("FROM");
}
- /* Complete "GRANT/REVOKE * ON * TO/FROM" with username, GROUP, or PUBLIC */
- else if (pg_strcasecmp(prev5_wd, "GRANT") == 0 &&
+ /*
+ * Complete "GRANT/REVOKE * ON ALL * IN SCHEMA * TO/FROM" with username,
+ * GROUP, or PUBLIC.
+ */
+ else if (((pg_strcasecmp(prev9_wd, "GRANT") == 0 && pg_strcasecmp(prev_wd, "TO") == 0) ||
+ (pg_strcasecmp(prev9_wd, "REVOKE") == 0 && pg_strcasecmp(prev_wd, "FROM") == 0)) &&
+ pg_strcasecmp(prev7_wd, "ON") == 0 &&
+ pg_strcasecmp(prev6_wd, "ALL") == 0 &&
+ pg_strcasecmp(prev4_wd, "IN") == 0 &&
+ pg_strcasecmp(prev3_wd, "SCHEMA") == 0)
+ COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+
+ /*
+ * Complete "GRANT/REVOKE * ON * * TO/FROM" with username, GROUP, or
+ * PUBLIC.
+ */
+ else if (((pg_strcasecmp(prev6_wd, "GRANT") == 0 && pg_strcasecmp(prev_wd, "TO") == 0) ||
+ (pg_strcasecmp(prev6_wd, "REVOKE") == 0 && pg_strcasecmp(prev_wd, "FROM") == 0)) &&
+ pg_strcasecmp(prev4_wd, "ON") == 0)
+ COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+
+ /*
+ * Complete "GRANT/REVOKE * ON * TO/FROM" with username, GROUP, or PUBLIC.
+ */
+ else if (((pg_strcasecmp(prev5_wd, "GRANT") == 0 && pg_strcasecmp(prev_wd, "TO") == 0) ||
+ (pg_strcasecmp(prev5_wd, "REVOKE") == 0 && pg_strcasecmp(prev_wd, "FROM") == 0)) &&
+ pg_strcasecmp(prev3_wd, "ON") == 0)
+ COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+
+ /* Complete "GRANT/REVOKE * ON * *" with TO or FROM */
+ else if ((pg_strcasecmp(prev5_wd, "GRANT") == 0 || pg_strcasecmp(prev5_wd, "REVOKE") == 0) &&
pg_strcasecmp(prev3_wd, "ON") == 0)
{
- if (pg_strcasecmp(prev_wd, "TO") == 0)
- COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
- else
+ if (pg_strcasecmp(prev5_wd, "GRANT") == 0)
COMPLETE_WITH_CONST("TO");
+ else
+ COMPLETE_WITH_CONST("FROM");
}
- else if (pg_strcasecmp(prev5_wd, "REVOKE") == 0 &&
- pg_strcasecmp(prev3_wd, "ON") == 0)
+
+ /* Complete "GRANT/REVOKE * ON ALL * IN SCHEMA *" with TO or FROM */
+ else if ((pg_strcasecmp(prev8_wd, "GRANT") == 0 || pg_strcasecmp(prev8_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev6_wd, "ON") == 0 &&
+ pg_strcasecmp(prev5_wd, "ALL") == 0 &&
+ pg_strcasecmp(prev3_wd, "IN") == 0 &&
+ pg_strcasecmp(prev2_wd, "SCHEMA") == 0)
{
- if (pg_strcasecmp(prev_wd, "FROM") == 0)
- COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+ if (pg_strcasecmp(prev8_wd, "GRANT") == 0)
+ COMPLETE_WITH_CONST("TO");
else
COMPLETE_WITH_CONST("FROM");
}
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-09-02 01:14 Michael Paquier <michael.paquier@gmail.com>
parent: Thomas Munro <thomas.munro@enterprisedb.com>
0 siblings, 1 reply; 19+ messages in thread
From: Michael Paquier @ 2015-09-02 01:14 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: Josh Berkus <josh@agliodbs.com>; pgsql-bugs
On Tue, Sep 1, 2015 at 10:15 PM, Thomas Munro wrote:
> Here is a version that splits that monster up into three small smaller
> blocks, and makes sure that GRANT goes with TO and REVOKE goes with FROM
> before completing with roles.
>
> Unfortunately your first example "GRANT ... FROM <tab>" still gets
> inappropriate completion because of the general FROM-matching branch with
> comment /* ... FROM ... */ that comes near the end, but it didn't seem
> sensible to start teaching the general FROM branch about avoiding this
> specific invalid production when it's happy to complete "BANANA FROM <tab>".
OK, let's live with that, tab completion would just have an incorrect
suggestion only once "from" is written completely with a space added
after it. Your patch improves many areas anyway, and that's just a
small point, hence let's have a committer look at it.
Regards,
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-09-03 12:02 Fujii Masao <masao.fujii@gmail.com>
parent: Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 19+ messages in thread
From: Fujii Masao @ 2015-09-03 12:02 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Thomas Munro <thomas.munro@enterprisedb.com>; Josh Berkus <josh@agliodbs.com>; pgsql-bugs
On Wed, Sep 2, 2015 at 10:14 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:
> On Tue, Sep 1, 2015 at 10:15 PM, Thomas Munro wrote:
>> Here is a version that splits that monster up into three small smaller
>> blocks, and makes sure that GRANT goes with TO and REVOKE goes with FROM
>> before completing with roles.
>>
>> Unfortunately your first example "GRANT ... FROM <tab>" still gets
>> inappropriate completion because of the general FROM-matching branch with
>> comment /* ... FROM ... */ that comes near the end, but it didn't seem
>> sensible to start teaching the general FROM branch about avoiding this
>> specific invalid production when it's happy to complete "BANANA FROM <tab>".
>
> OK, let's live with that, tab completion would just have an incorrect
> suggestion only once "from" is written completely with a space added
> after it. Your patch improves many areas anyway, and that's just a
> small point, hence let's have a committer look at it.
"GRANT xxx ON FOREIGN DATA WRAPPER yyy <tab>" should suggest "TO"?
"GRANT xxx ON FOREIGN DATA WRAPPER yyy TO <tab>" should suggest the roles?
"GRANT xxx ON FOREIGN SERVER <tab>" should suggest foreign servers?
"GRANT xxx ON FOREIGN SERVER yyy <tab>" should suggest "TO"?
"GRANT xxx ON FOREIGN SERVER yyy TO <tab>" should suggest the roles?
Regards,
--
Fujii Masao
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-09-03 22:24 Thomas Munro <thomas.munro@enterprisedb.com>
parent: Fujii Masao <masao.fujii@gmail.com>
0 siblings, 1 reply; 19+ messages in thread
From: Thomas Munro @ 2015-09-03 22:24 UTC (permalink / raw)
To: Fujii Masao <masao.fujii@gmail.com>; +Cc: Michael Paquier <michael.paquier@gmail.com>; Josh Berkus <josh@agliodbs.com>; pgsql-bugs
On Fri, Sep 4, 2015 at 12:02 AM, Fujii Masao <masao.fujii@gmail.com> wrote:
> On Wed, Sep 2, 2015 at 10:14 AM, Michael Paquier
> <michael.paquier@gmail.com> wrote:
> > On Tue, Sep 1, 2015 at 10:15 PM, Thomas Munro wrote:
> >> Here is a version that splits that monster up into three small smaller
> >> blocks, and makes sure that GRANT goes with TO and REVOKE goes with FROM
> >> before completing with roles.
> >>
> >> Unfortunately your first example "GRANT ... FROM <tab>" still gets
> >> inappropriate completion because of the general FROM-matching branch
> with
> >> comment /* ... FROM ... */ that comes near the end, but it didn't seem
> >> sensible to start teaching the general FROM branch about avoiding this
> >> specific invalid production when it's happy to complete "BANANA FROM
> <tab>".
> >
> > OK, let's live with that, tab completion would just have an incorrect
> > suggestion only once "from" is written completely with a space added
> > after it. Your patch improves many areas anyway, and that's just a
> > small point, hence let's have a committer look at it.
>
> "GRANT xxx ON FOREIGN DATA WRAPPER yyy <tab>" should suggest "TO"?
> "GRANT xxx ON FOREIGN DATA WRAPPER yyy TO <tab>" should suggest the roles?
> "GRANT xxx ON FOREIGN SERVER <tab>" should suggest foreign servers?
> "GRANT xxx ON FOREIGN SERVER yyy <tab>" should suggest "TO"?
> "GRANT xxx ON FOREIGN SERVER yyy TO <tab>" should suggest the roles?
>
Thanks. New version attached that handles these to.
Also fixed "GRANT * ON FOREIGN DATA <tab>" which now suggests "WRAPPER".
--
Thomas Munro
http://www.enterprisedb.com
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
tab-complete-grant-v3.patch (application/octet-stream, 8.5K) download
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 816deda..c00308d 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -888,7 +888,7 @@ psql_completion(const char *text, int start, int end)
char **matches = NULL;
/* This array will contain some scannage of the input line. */
- char *previous_words[6];
+ char *previous_words[9];
/* For compactness, we use these macros to reference previous_words[]. */
#define prev_wd (previous_words[0])
@@ -897,6 +897,9 @@ psql_completion(const char *text, int start, int end)
#define prev4_wd (previous_words[3])
#define prev5_wd (previous_words[4])
#define prev6_wd (previous_words[5])
+#define prev7_wd (previous_words[6])
+#define prev8_wd (previous_words[7])
+#define prev9_wd (previous_words[8])
static const char *const sql_commands[] = {
"ABORT", "ALTER", "ANALYZE", "BEGIN", "CHECKPOINT", "CLOSE", "CLUSTER",
@@ -3132,6 +3135,9 @@ psql_completion(const char *text, int start, int end)
pg_strcasecmp(prev3_wd, "REVOKE") == 0) &&
pg_strcasecmp(prev_wd, "ON") == 0)
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tsvmf,
+ " UNION SELECT 'ALL FUNCTIONS IN SCHEMA'"
+ " UNION SELECT 'ALL SEQUENCES IN SCHEMA'"
+ " UNION SELECT 'ALL TABLES IN SCHEMA'"
" UNION SELECT 'DATABASE'"
" UNION SELECT 'DOMAIN'"
" UNION SELECT 'FOREIGN DATA WRAPPER'"
@@ -3140,11 +3146,24 @@ psql_completion(const char *text, int start, int end)
" UNION SELECT 'LANGUAGE'"
" UNION SELECT 'LARGE OBJECT'"
" UNION SELECT 'SCHEMA'"
+ " UNION SELECT 'SEQUENCE'"
+ " UNION SELECT 'TABLE'"
" UNION SELECT 'TABLESPACE'"
" UNION SELECT 'TYPE'");
else if ((pg_strcasecmp(prev4_wd, "GRANT") == 0 ||
pg_strcasecmp(prev4_wd, "REVOKE") == 0) &&
pg_strcasecmp(prev2_wd, "ON") == 0 &&
+ pg_strcasecmp(prev_wd, "ALL") == 0)
+ {
+ static const char *const list_privilege_all[] =
+ {"FUNCTIONS IN SCHEMA", "SEQUENCES IN SCHEMA", "TABLES IN SCHEMA", NULL};
+
+ COMPLETE_WITH_LIST(list_privilege_all);
+ }
+
+ else if ((pg_strcasecmp(prev4_wd, "GRANT") == 0 ||
+ pg_strcasecmp(prev4_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev2_wd, "ON") == 0 &&
pg_strcasecmp(prev_wd, "FOREIGN") == 0)
{
static const char *const list_privilege_foreign[] =
@@ -3153,7 +3172,19 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_LIST(list_privilege_foreign);
}
- /* Complete "GRANT/REVOKE * ON * " with "TO/FROM" */
+ /* Complete "GRANT/REVOKE * ON FOREIGN DATA" with WRAPPER */
+ else if ((pg_strcasecmp(prev5_wd, "GRANT") == 0 || pg_strcasecmp(prev5_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev3_wd, "ON") == 0 &&
+ pg_strcasecmp(prev2_wd, "FOREIGN") == 0 &&
+ pg_strcasecmp(prev_wd, "DATA") == 0)
+ COMPLETE_WITH_CONST("WRAPPER");
+
+ /*
+ * Complete "GRANT/REMOVE * ON DATABASE/DOMAIN/..." with a list of
+ * appropriate objects.
+ *
+ * Complete "GRANT/REVOKE * ON * " with "TO/FROM".
+ */
else if ((pg_strcasecmp(prev4_wd, "GRANT") == 0 ||
pg_strcasecmp(prev4_wd, "REVOKE") == 0) &&
pg_strcasecmp(prev2_wd, "ON") == 0)
@@ -3168,6 +3199,10 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_QUERY(Query_for_list_of_languages);
else if (pg_strcasecmp(prev_wd, "SCHEMA") == 0)
COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
+ else if (pg_strcasecmp(prev_wd, "SEQUENCE") == 0)
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_sequences, NULL);
+ else if (pg_strcasecmp(prev_wd, "TABLE") == 0)
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
else if (pg_strcasecmp(prev_wd, "TABLESPACE") == 0)
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
else if (pg_strcasecmp(prev_wd, "TYPE") == 0)
@@ -3178,20 +3213,109 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_CONST("FROM");
}
- /* Complete "GRANT/REVOKE * ON * TO/FROM" with username, GROUP, or PUBLIC */
- else if (pg_strcasecmp(prev5_wd, "GRANT") == 0 &&
+ /*
+ * Complete "GRANT/REVOKE * ON ALL * IN SCHEMA * TO/FROM" with username,
+ * GROUP, or PUBLIC.
+ */
+ else if (((pg_strcasecmp(prev9_wd, "GRANT") == 0 && pg_strcasecmp(prev_wd, "TO") == 0) ||
+ (pg_strcasecmp(prev9_wd, "REVOKE") == 0 && pg_strcasecmp(prev_wd, "FROM") == 0)) &&
+ pg_strcasecmp(prev7_wd, "ON") == 0 &&
+ pg_strcasecmp(prev6_wd, "ALL") == 0 &&
+ pg_strcasecmp(prev4_wd, "IN") == 0 &&
+ pg_strcasecmp(prev3_wd, "SCHEMA") == 0)
+ COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+
+ /* Complete "GRANT/REVOKE * ON FOREIGN SERVER" with server names. */
+ else if ((pg_strcasecmp(prev5_wd, "GRANT") == 0 || pg_strcasecmp(prev5_wd, "REVOKE")) &&
+ pg_strcasecmp(prev3_wd, "ON") == 0 &&
+ pg_strcasecmp(prev2_wd, "FOREIGN") == 0 &&
+ pg_strcasecmp(prev_wd, "SERVER") == 0)
+ COMPLETE_WITH_QUERY(Query_for_list_of_servers);
+
+ /*
+ * Complete "GRANT/REVOKE * ON FOREIGN DATA WRAPPER * TO/FROM" with username,
+ * GROUP, or PUBLIC.
+ */
+ else if (((pg_strcasecmp(prev8_wd, "GRANT") == 0 && pg_strcasecmp(prev_wd, "TO") == 0) ||
+ (pg_strcasecmp(prev8_wd, "REVOKE") == 0 && pg_strcasecmp(prev_wd, "FROM") == 0)) &&
+ pg_strcasecmp(prev6_wd, "ON") == 0 &&
+ pg_strcasecmp(prev5_wd, "FOREIGN") == 0 &&
+ pg_strcasecmp(prev4_wd, "DATA") == 0 &&
+ pg_strcasecmp(prev3_wd, "WRAPPER") == 0)
+ COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+
+ /*
+ * Complete "GRANT/REVOKE * ON FOREIGN SERVER * TO/FROM" with username,
+ * GROUP, or PUBLIC.
+ */
+ else if (((pg_strcasecmp(prev7_wd, "GRANT") == 0 && pg_strcasecmp(prev_wd, "TO") == 0) ||
+ (pg_strcasecmp(prev7_wd, "REVOKE") == 0 && pg_strcasecmp(prev_wd, "FROM") == 0)) &&
+ pg_strcasecmp(prev5_wd, "ON") == 0 &&
+ pg_strcasecmp(prev4_wd, "FOREIGN") == 0 &&
+ pg_strcasecmp(prev3_wd, "SERVER") == 0)
+ COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+
+ /*
+ * Complete "GRANT/REVOKE * ON * * TO/FROM" with username, GROUP, or
+ * PUBLIC.
+ */
+ else if (((pg_strcasecmp(prev6_wd, "GRANT") == 0 && pg_strcasecmp(prev_wd, "TO") == 0) ||
+ (pg_strcasecmp(prev6_wd, "REVOKE") == 0 && pg_strcasecmp(prev_wd, "FROM") == 0)) &&
+ pg_strcasecmp(prev4_wd, "ON") == 0)
+ COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+
+ /*
+ * Complete "GRANT/REVOKE * ON * TO/FROM" with username, GROUP, or PUBLIC.
+ */
+ else if (((pg_strcasecmp(prev5_wd, "GRANT") == 0 && pg_strcasecmp(prev_wd, "TO") == 0) ||
+ (pg_strcasecmp(prev5_wd, "REVOKE") == 0 && pg_strcasecmp(prev_wd, "FROM") == 0)) &&
+ pg_strcasecmp(prev3_wd, "ON") == 0)
+ COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+
+ /* Complete "GRANT/REVOKE * ON * *" with TO or FROM */
+ else if ((pg_strcasecmp(prev5_wd, "GRANT") == 0 || pg_strcasecmp(prev5_wd, "REVOKE") == 0) &&
pg_strcasecmp(prev3_wd, "ON") == 0)
{
- if (pg_strcasecmp(prev_wd, "TO") == 0)
- COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+ if (pg_strcasecmp(prev5_wd, "GRANT") == 0)
+ COMPLETE_WITH_CONST("TO");
else
+ COMPLETE_WITH_CONST("FROM");
+ }
+
+ /* Complete "GRANT/REVOKE * ON ALL * IN SCHEMA *" with TO or FROM */
+ else if ((pg_strcasecmp(prev8_wd, "GRANT") == 0 || pg_strcasecmp(prev8_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev6_wd, "ON") == 0 &&
+ pg_strcasecmp(prev5_wd, "ALL") == 0 &&
+ pg_strcasecmp(prev3_wd, "IN") == 0 &&
+ pg_strcasecmp(prev2_wd, "SCHEMA") == 0)
+ {
+ if (pg_strcasecmp(prev8_wd, "GRANT") == 0)
COMPLETE_WITH_CONST("TO");
+ else
+ COMPLETE_WITH_CONST("FROM");
}
- else if (pg_strcasecmp(prev5_wd, "REVOKE") == 0 &&
- pg_strcasecmp(prev3_wd, "ON") == 0)
+
+ /* Complete "GRANT/REVOKE * ON FOREIGN DATA WRAPPER *" with TO or FROM */
+ else if ((pg_strcasecmp(prev7_wd, "GRANT") == 0 || pg_strcasecmp(prev7_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev5_wd, "ON") == 0 &&
+ pg_strcasecmp(prev4_wd, "FOREIGN") == 0 &&
+ pg_strcasecmp(prev3_wd, "DATA") == 0 &&
+ pg_strcasecmp(prev2_wd, "WRAPPER") == 0)
{
- if (pg_strcasecmp(prev_wd, "FROM") == 0)
- COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+ if (pg_strcasecmp(prev7_wd, "GRANT") == 0)
+ COMPLETE_WITH_CONST("TO");
+ else
+ COMPLETE_WITH_CONST("FROM");
+ }
+
+ /* Complete "GRANT/REVOKE * ON FOREIGN SERVER *" with TO or FROM */
+ else if ((pg_strcasecmp(prev6_wd, "GRANT") == 0 || pg_strcasecmp(prev6_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev4_wd, "ON") == 0 &&
+ pg_strcasecmp(prev3_wd, "FOREIGN") == 0 &&
+ pg_strcasecmp(prev2_wd, "SERVER") == 0)
+ {
+ if (pg_strcasecmp(prev6_wd, "GRANT") == 0)
+ COMPLETE_WITH_CONST("TO");
else
COMPLETE_WITH_CONST("FROM");
}
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-09-04 08:16 Fujii Masao <masao.fujii@gmail.com>
parent: Thomas Munro <thomas.munro@enterprisedb.com>
0 siblings, 1 reply; 19+ messages in thread
From: Fujii Masao @ 2015-09-04 08:16 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: Michael Paquier <michael.paquier@gmail.com>; Josh Berkus <josh@agliodbs.com>; pgsql-bugs
On Fri, Sep 4, 2015 at 7:24 AM, Thomas Munro
<thomas.munro@enterprisedb.com> wrote:
> On Fri, Sep 4, 2015 at 12:02 AM, Fujii Masao <masao.fujii@gmail.com> wrote:
>>
>> On Wed, Sep 2, 2015 at 10:14 AM, Michael Paquier
>> <michael.paquier@gmail.com> wrote:
>> > On Tue, Sep 1, 2015 at 10:15 PM, Thomas Munro wrote:
>> >> Here is a version that splits that monster up into three small smaller
>> >> blocks, and makes sure that GRANT goes with TO and REVOKE goes with
>> >> FROM
>> >> before completing with roles.
>> >>
>> >> Unfortunately your first example "GRANT ... FROM <tab>" still gets
>> >> inappropriate completion because of the general FROM-matching branch
>> >> with
>> >> comment /* ... FROM ... */ that comes near the end, but it didn't seem
>> >> sensible to start teaching the general FROM branch about avoiding this
>> >> specific invalid production when it's happy to complete "BANANA FROM
>> >> <tab>".
>> >
>> > OK, let's live with that, tab completion would just have an incorrect
>> > suggestion only once "from" is written completely with a space added
>> > after it. Your patch improves many areas anyway, and that's just a
>> > small point, hence let's have a committer look at it.
>>
>> "GRANT xxx ON FOREIGN DATA WRAPPER yyy <tab>" should suggest "TO"?
>> "GRANT xxx ON FOREIGN DATA WRAPPER yyy TO <tab>" should suggest the roles?
>> "GRANT xxx ON FOREIGN SERVER <tab>" should suggest foreign servers?
>> "GRANT xxx ON FOREIGN SERVER yyy <tab>" should suggest "TO"?
>> "GRANT xxx ON FOREIGN SERVER yyy TO <tab>" should suggest the roles?
>
>
> Thanks. New version attached that handles these to.
Thanks for updating the patch!
Attached is the updated version of the patch. Could you review this?
> Also fixed "GRANT * ON FOREIGN DATA <tab>" which now suggests "WRAPPER".
Isn't this overkill? Otherwise, for example, "GRANT * ON ALL FUNCTIONS <tab>"
should suggest "IN", and then "GRANT * ON ALL FUNCTIONS IN <tab>" should
suggest "SCHEMA" for the sake of consistency. They seem overkill to me.
So I removed the code related to this from the patch.
+ else if (pg_strcasecmp(prev_wd, "TABLE") == 0)
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
Not only ordinary table but also ordinary view, materialized view,
foreign table, and sequence can follow the keyword TABLE. So I modified
the patch so that Query_for_list_of_tsvmf is used here, instead.
+ /*
+ * Complete "GRANT/REVOKE * ON ALL * IN SCHEMA * TO/FROM" with username,
+ * GROUP, or PUBLIC.
+ */
In 9.5 or later, CURRENT_USER or SESSION_USER keyword can follow TO/FROM.
So I added them into Query_for_list_of_grant_roles, and changed the above
comment.
+ else if (((pg_strcasecmp(prev9_wd, "GRANT") == 0 &&
pg_strcasecmp(prev_wd, "TO") == 0) ||
+ (pg_strcasecmp(prev9_wd, "REVOKE") == 0 &&
pg_strcasecmp(prev_wd, "FROM") == 0)) &&
+ pg_strcasecmp(prev7_wd, "ON") == 0 &&
+ pg_strcasecmp(prev6_wd, "ALL") == 0 &&
+ pg_strcasecmp(prev4_wd, "IN") == 0 &&
+ pg_strcasecmp(prev3_wd, "SCHEMA") == 0)
+ COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
Do we really need to check the keywords other than GRANT, REVOKE, TO and FROM?
You added several similar tab-completion codes like that, but I think that
we can refactor them so that only GRANT, REVOKE, TO and FROM are checked.
I applied that refactoring to the patch.
Regards,
--
Fujii Masao
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
tab-complete-grant-v4.patch (text/x-patch, 8.1K) download
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 816deda..cd9254c 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 \
@@ -888,7 +890,7 @@ psql_completion(const char *text, int start, int end)
char **matches = NULL;
/* This array will contain some scannage of the input line. */
- char *previous_words[6];
+ char *previous_words[9];
/* For compactness, we use these macros to reference previous_words[]. */
#define prev_wd (previous_words[0])
@@ -897,6 +899,9 @@ psql_completion(const char *text, int start, int end)
#define prev4_wd (previous_words[3])
#define prev5_wd (previous_words[4])
#define prev6_wd (previous_words[5])
+#define prev7_wd (previous_words[6])
+#define prev8_wd (previous_words[7])
+#define prev9_wd (previous_words[8])
static const char *const sql_commands[] = {
"ABORT", "ALTER", "ANALYZE", "BEGIN", "CHECKPOINT", "CLOSE", "CLUSTER",
@@ -3065,6 +3070,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 ||
@@ -3118,20 +3128,23 @@ psql_completion(const char *text, int start, int end)
}
/*
- * Complete GRANT/REVOKE <sth> ON with a list of tables, views, sequences,
- * and indexes
+ * Complete GRANT/REVOKE <sth> ON with a list of tables, views, and
+ * sequences.
*
- * keywords DATABASE, FUNCTION, LANGUAGE, SCHEMA added to query result via
- * UNION; seems to work intuitively
+ * Keywords like DATABASE, FUNCTION, LANGUAGE and SCHEMA added to
+ * query result via UNION; seems to work intuitively.
*
* Note: GRANT/REVOKE can get quite complex; tab-completion as implemented
* here will only work if the privilege list contains exactly one
- * privilege
+ * privilege.
*/
else if ((pg_strcasecmp(prev3_wd, "GRANT") == 0 ||
pg_strcasecmp(prev3_wd, "REVOKE") == 0) &&
pg_strcasecmp(prev_wd, "ON") == 0)
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tsvmf,
+ " UNION SELECT 'ALL FUNCTIONS IN SCHEMA'"
+ " UNION SELECT 'ALL SEQUENCES IN SCHEMA'"
+ " UNION SELECT 'ALL TABLES IN SCHEMA'"
" UNION SELECT 'DATABASE'"
" UNION SELECT 'DOMAIN'"
" UNION SELECT 'FOREIGN DATA WRAPPER'"
@@ -3140,8 +3153,23 @@ psql_completion(const char *text, int start, int end)
" UNION SELECT 'LANGUAGE'"
" UNION SELECT 'LARGE OBJECT'"
" UNION SELECT 'SCHEMA'"
+ " UNION SELECT 'SEQUENCE'"
+ " UNION SELECT 'TABLE'"
" UNION SELECT 'TABLESPACE'"
" UNION SELECT 'TYPE'");
+
+ else if ((pg_strcasecmp(prev4_wd, "GRANT") == 0 ||
+ pg_strcasecmp(prev4_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev2_wd, "ON") == 0 &&
+ pg_strcasecmp(prev_wd, "ALL") == 0)
+ {
+ static const char *const list_privilege_all[] =
+ {"FUNCTIONS IN SCHEMA", "SEQUENCES IN SCHEMA", "TABLES IN SCHEMA",
+ NULL};
+
+ COMPLETE_WITH_LIST(list_privilege_all);
+ }
+
else if ((pg_strcasecmp(prev4_wd, "GRANT") == 0 ||
pg_strcasecmp(prev4_wd, "REVOKE") == 0) &&
pg_strcasecmp(prev2_wd, "ON") == 0 &&
@@ -3153,7 +3181,12 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_LIST(list_privilege_foreign);
}
- /* Complete "GRANT/REVOKE * ON * " with "TO/FROM" */
+ /*
+ * Complete "GRANT/REMOVE * ON DATABASE/DOMAIN/..." with a list of
+ * appropriate objects.
+ *
+ * Complete "GRANT/REVOKE * ON * " with "TO/FROM".
+ */
else if ((pg_strcasecmp(prev4_wd, "GRANT") == 0 ||
pg_strcasecmp(prev4_wd, "REVOKE") == 0) &&
pg_strcasecmp(prev2_wd, "ON") == 0)
@@ -3168,6 +3201,10 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_QUERY(Query_for_list_of_languages);
else if (pg_strcasecmp(prev_wd, "SCHEMA") == 0)
COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
+ else if (pg_strcasecmp(prev_wd, "SEQUENCE") == 0)
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_sequences, NULL);
+ else if (pg_strcasecmp(prev_wd, "TABLE") == 0)
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tsvmf, NULL);
else if (pg_strcasecmp(prev_wd, "TABLESPACE") == 0)
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
else if (pg_strcasecmp(prev_wd, "TYPE") == 0)
@@ -3178,25 +3215,78 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_CONST("FROM");
}
- /* Complete "GRANT/REVOKE * ON * TO/FROM" with username, GROUP, or PUBLIC */
+ /* Complete "GRANT/REVOKE * ON * *" with TO/FROM */
else if (pg_strcasecmp(prev5_wd, "GRANT") == 0 &&
pg_strcasecmp(prev3_wd, "ON") == 0)
+ COMPLETE_WITH_CONST("TO");
+
+ else if (pg_strcasecmp(prev5_wd, "REVOKE") == 0 &&
+ pg_strcasecmp(prev3_wd, "ON") == 0)
+ COMPLETE_WITH_CONST("FROM");
+
+ /* Complete "GRANT/REVOKE * ON ALL * IN SCHEMA *" with TO/FROM */
+ else if ((pg_strcasecmp(prev8_wd, "GRANT") == 0 ||
+ pg_strcasecmp(prev8_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev6_wd, "ON") == 0 &&
+ pg_strcasecmp(prev5_wd, "ALL") == 0 &&
+ pg_strcasecmp(prev3_wd, "IN") == 0 &&
+ pg_strcasecmp(prev2_wd, "SCHEMA") == 0)
{
- if (pg_strcasecmp(prev_wd, "TO") == 0)
- COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+ if (pg_strcasecmp(prev8_wd, "GRANT") == 0)
+ COMPLETE_WITH_CONST("TO");
else
+ COMPLETE_WITH_CONST("FROM");
+ }
+
+ /* Complete "GRANT/REVOKE * ON FOREIGN DATA WRAPPER *" with TO/FROM */
+ else if ((pg_strcasecmp(prev7_wd, "GRANT") == 0 ||
+ pg_strcasecmp(prev7_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev5_wd, "ON") == 0 &&
+ pg_strcasecmp(prev4_wd, "FOREIGN") == 0 &&
+ pg_strcasecmp(prev3_wd, "DATA") == 0 &&
+ pg_strcasecmp(prev2_wd, "WRAPPER") == 0)
+ {
+ if (pg_strcasecmp(prev7_wd, "GRANT") == 0)
COMPLETE_WITH_CONST("TO");
+ else
+ COMPLETE_WITH_CONST("FROM");
}
- else if (pg_strcasecmp(prev5_wd, "REVOKE") == 0 &&
- pg_strcasecmp(prev3_wd, "ON") == 0)
+
+ /* Complete "GRANT/REVOKE * ON FOREIGN SERVER *" with TO/FROM */
+ else if ((pg_strcasecmp(prev6_wd, "GRANT") == 0 ||
+ pg_strcasecmp(prev6_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev4_wd, "ON") == 0 &&
+ pg_strcasecmp(prev3_wd, "FOREIGN") == 0 &&
+ pg_strcasecmp(prev2_wd, "SERVER") == 0)
{
- if (pg_strcasecmp(prev_wd, "FROM") == 0)
- COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+ if (pg_strcasecmp(prev6_wd, "GRANT") == 0)
+ COMPLETE_WITH_CONST("TO");
else
COMPLETE_WITH_CONST("FROM");
}
- /* Complete "GRANT/REVOKE * TO/FROM" with username, GROUP, or PUBLIC */
+ /*
+ * Complete "GRANT/REVOKE ... TO/FROM" with username, PUBLIC,
+ * CURRENT_USER, or SESSION_USER.
+ */
+ else if (((pg_strcasecmp(prev9_wd, "GRANT") == 0 ||
+ pg_strcasecmp(prev8_wd, "GRANT") == 0 ||
+ pg_strcasecmp(prev7_wd, "GRANT") == 0 ||
+ pg_strcasecmp(prev6_wd, "GRANT") == 0 ||
+ pg_strcasecmp(prev5_wd, "GRANT") == 0) &&
+ pg_strcasecmp(prev_wd, "TO") == 0) ||
+ ((pg_strcasecmp(prev9_wd, "REVOKE") == 0 ||
+ pg_strcasecmp(prev8_wd, "REVOKE") == 0 ||
+ pg_strcasecmp(prev7_wd, "REVOKE") == 0 ||
+ pg_strcasecmp(prev6_wd, "REVOKE") == 0 ||
+ pg_strcasecmp(prev5_wd, "REVOKE") == 0) &&
+ pg_strcasecmp(prev_wd, "FROM") == 0))
+ COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+
+ /*
+ * Complete "GRANT/REVOKE * TO/FROM" with username, PUBLIC,
+ * CURRENT_USER, or SESSION_USER.
+ */
else if (pg_strcasecmp(prev3_wd, "GRANT") == 0 &&
pg_strcasecmp(prev_wd, "TO") == 0)
{
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-09-05 12:43 Thomas Munro <thomas.munro@enterprisedb.com>
parent: Fujii Masao <masao.fujii@gmail.com>
0 siblings, 1 reply; 19+ messages in thread
From: Thomas Munro @ 2015-09-05 12:43 UTC (permalink / raw)
To: Fujii Masao <masao.fujii@gmail.com>; +Cc: Michael Paquier <michael.paquier@gmail.com>; Josh Berkus <josh@agliodbs.com>; pgsql-bugs
On Fri, Sep 4, 2015 at 8:16 PM, Fujii Masao <masao.fujii@gmail.com> wrote:
> On Fri, Sep 4, 2015 at 7:24 AM, Thomas Munro
> <thomas.munro@enterprisedb.com> wrote:
> > On Fri, Sep 4, 2015 at 12:02 AM, Fujii Masao <masao.fujii@gmail.com>
> wrote:
> >>
> >> On Wed, Sep 2, 2015 at 10:14 AM, Michael Paquier
> >> <michael.paquier@gmail.com> wrote:
> >> > On Tue, Sep 1, 2015 at 10:15 PM, Thomas Munro wrote:
> >> >> Here is a version that splits that monster up into three small
> smaller
> >> >> blocks, and makes sure that GRANT goes with TO and REVOKE goes with
> >> >> FROM
> >> >> before completing with roles.
> >> >>
> >> >> Unfortunately your first example "GRANT ... FROM <tab>" still gets
> >> >> inappropriate completion because of the general FROM-matching branch
> >> >> with
> >> >> comment /* ... FROM ... */ that comes near the end, but it didn't
> seem
> >> >> sensible to start teaching the general FROM branch about avoiding
> this
> >> >> specific invalid production when it's happy to complete "BANANA FROM
> >> >> <tab>".
> >> >
> >> > OK, let's live with that, tab completion would just have an incorrect
> >> > suggestion only once "from" is written completely with a space added
> >> > after it. Your patch improves many areas anyway, and that's just a
> >> > small point, hence let's have a committer look at it.
> >>
> >> "GRANT xxx ON FOREIGN DATA WRAPPER yyy <tab>" should suggest "TO"?
> >> "GRANT xxx ON FOREIGN DATA WRAPPER yyy TO <tab>" should suggest the
> roles?
> >> "GRANT xxx ON FOREIGN SERVER <tab>" should suggest foreign servers?
> >> "GRANT xxx ON FOREIGN SERVER yyy <tab>" should suggest "TO"?
> >> "GRANT xxx ON FOREIGN SERVER yyy TO <tab>" should suggest the roles?
> >
> >
> > Thanks. New version attached that handles these to.
>
> Thanks for updating the patch!
> Attached is the updated version of the patch. Could you review this?
Thanks for the review and the improvements!
> > Also fixed "GRANT * ON FOREIGN DATA <tab>" which now suggests "WRAPPER".
>
> Isn't this overkill? Otherwise, for example, "GRANT * ON ALL FUNCTIONS
> <tab>"
> should suggest "IN", and then "GRANT * ON ALL FUNCTIONS IN <tab>" should
> suggest "SCHEMA" for the sake of consistency. They seem overkill to me.
> So I removed the code related to this from the patch.
>
Fair enough.
> + else if (pg_strcasecmp(prev_wd, "TABLE") == 0)
> + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
>
> Not only ordinary table but also ordinary view, materialized view,
> foreign table, and sequence can follow the keyword TABLE. So I modified
> the patch so that Query_for_list_of_tsvmf is used here, instead.
>
> + /*
> + * Complete "GRANT/REVOKE * ON ALL * IN SCHEMA * TO/FROM" with
> username,
> + * GROUP, or PUBLIC.
> + */
>
> In 9.5 or later, CURRENT_USER or SESSION_USER keyword can follow TO/FROM.
> So I added them into Query_for_list_of_grant_roles, and changed the above
> comment.
>
Good catch.
> + else if (((pg_strcasecmp(prev9_wd, "GRANT") == 0 &&
> pg_strcasecmp(prev_wd, "TO") == 0) ||
> + (pg_strcasecmp(prev9_wd, "REVOKE") == 0 &&
> pg_strcasecmp(prev_wd, "FROM") == 0)) &&
> + pg_strcasecmp(prev7_wd, "ON") == 0 &&
> + pg_strcasecmp(prev6_wd, "ALL") == 0 &&
> + pg_strcasecmp(prev4_wd, "IN") == 0 &&
> + pg_strcasecmp(prev3_wd, "SCHEMA") == 0)
> + COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
>
> Do we really need to check the keywords other than GRANT, REVOKE, TO and
> FROM?
> You added several similar tab-completion codes like that, but I think that
> we can refactor them so that only GRANT, REVOKE, TO and FROM are checked.
> I applied that refactoring to the patch.
>
+1
--
Thomas Munro
http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-09-08 17:02 Fujii Masao <masao.fujii@gmail.com>
parent: Thomas Munro <thomas.munro@enterprisedb.com>
0 siblings, 1 reply; 19+ messages in thread
From: Fujii Masao @ 2015-09-08 17:02 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: Michael Paquier <michael.paquier@gmail.com>; Josh Berkus <josh@agliodbs.com>; pgsql-bugs
On Sat, Sep 5, 2015 at 9:43 PM, Thomas Munro
<thomas.munro@enterprisedb.com> wrote:
> On Fri, Sep 4, 2015 at 8:16 PM, Fujii Masao <masao.fujii@gmail.com> wrote:
>>
>> On Fri, Sep 4, 2015 at 7:24 AM, Thomas Munro
>> <thomas.munro@enterprisedb.com> wrote:
>> > On Fri, Sep 4, 2015 at 12:02 AM, Fujii Masao <masao.fujii@gmail.com>
>> > wrote:
>> >>
>> >> On Wed, Sep 2, 2015 at 10:14 AM, Michael Paquier
>> >> <michael.paquier@gmail.com> wrote:
>> >> > On Tue, Sep 1, 2015 at 10:15 PM, Thomas Munro wrote:
>> >> >> Here is a version that splits that monster up into three small
>> >> >> smaller
>> >> >> blocks, and makes sure that GRANT goes with TO and REVOKE goes with
>> >> >> FROM
>> >> >> before completing with roles.
>> >> >>
>> >> >> Unfortunately your first example "GRANT ... FROM <tab>" still gets
>> >> >> inappropriate completion because of the general FROM-matching branch
>> >> >> with
>> >> >> comment /* ... FROM ... */ that comes near the end, but it didn't
>> >> >> seem
>> >> >> sensible to start teaching the general FROM branch about avoiding
>> >> >> this
>> >> >> specific invalid production when it's happy to complete "BANANA FROM
>> >> >> <tab>".
>> >> >
>> >> > OK, let's live with that, tab completion would just have an incorrect
>> >> > suggestion only once "from" is written completely with a space added
>> >> > after it. Your patch improves many areas anyway, and that's just a
>> >> > small point, hence let's have a committer look at it.
>> >>
>> >> "GRANT xxx ON FOREIGN DATA WRAPPER yyy <tab>" should suggest "TO"?
>> >> "GRANT xxx ON FOREIGN DATA WRAPPER yyy TO <tab>" should suggest the
>> >> roles?
>> >> "GRANT xxx ON FOREIGN SERVER <tab>" should suggest foreign servers?
>> >> "GRANT xxx ON FOREIGN SERVER yyy <tab>" should suggest "TO"?
>> >> "GRANT xxx ON FOREIGN SERVER yyy TO <tab>" should suggest the roles?
>> >
>> >
>> > Thanks. New version attached that handles these to.
>>
>> Thanks for updating the patch!
>> Attached is the updated version of the patch. Could you review this?
>
>
> Thanks for the review and the improvements!
So applied. Thanks a lot!
Regards,
--
Fujii Masao
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-09-29 16:59 Jeff Janes <jeff.janes@gmail.com>
parent: Fujii Masao <masao.fujii@gmail.com>
0 siblings, 1 reply; 19+ messages in thread
From: Jeff Janes @ 2015-09-29 16:59 UTC (permalink / raw)
To: Fujii Masao <masao.fujii@gmail.com>; +Cc: Thomas Munro <thomas.munro@enterprisedb.com>; Michael Paquier <michael.paquier@gmail.com>; Josh Berkus <josh@agliodbs.com>; pgsql-bugs
On Tue, Sep 8, 2015 at 10:02 AM, Fujii Masao <masao.fujii@gmail.com> wrote:
> On Sat, Sep 5, 2015 at 9:43 PM, Thomas Munro
> <thomas.munro@enterprisedb.com> wrote:
> > On Fri, Sep 4, 2015 at 8:16 PM, Fujii Masao <masao.fujii@gmail.com>
> wrote:
> >>
> >> On Fri, Sep 4, 2015 at 7:24 AM, Thomas Munro
> >> <thomas.munro@enterprisedb.com> wrote:
> >> > On Fri, Sep 4, 2015 at 12:02 AM, Fujii Masao <masao.fujii@gmail.com>
> >> > wrote:
> >> >>
> >> >> On Wed, Sep 2, 2015 at 10:14 AM, Michael Paquier
> >> >> <michael.paquier@gmail.com> wrote:
> >> >> > On Tue, Sep 1, 2015 at 10:15 PM, Thomas Munro wrote:
> >> >> >> Here is a version that splits that monster up into three small
> >> >> >> smaller
> >> >> >> blocks, and makes sure that GRANT goes with TO and REVOKE goes
> with
> >> >> >> FROM
> >> >> >> before completing with roles.
> >> >> >>
> >> >> >> Unfortunately your first example "GRANT ... FROM <tab>" still gets
> >> >> >> inappropriate completion because of the general FROM-matching
> branch
> >> >> >> with
> >> >> >> comment /* ... FROM ... */ that comes near the end, but it didn't
> >> >> >> seem
> >> >> >> sensible to start teaching the general FROM branch about avoiding
> >> >> >> this
> >> >> >> specific invalid production when it's happy to complete "BANANA
> FROM
> >> >> >> <tab>".
> >> >> >
> >> >> > OK, let's live with that, tab completion would just have an
> incorrect
> >> >> > suggestion only once "from" is written completely with a space
> added
> >> >> > after it. Your patch improves many areas anyway, and that's just a
> >> >> > small point, hence let's have a committer look at it.
> >> >>
> >> >> "GRANT xxx ON FOREIGN DATA WRAPPER yyy <tab>" should suggest "TO"?
> >> >> "GRANT xxx ON FOREIGN DATA WRAPPER yyy TO <tab>" should suggest the
> >> >> roles?
> >> >> "GRANT xxx ON FOREIGN SERVER <tab>" should suggest foreign servers?
> >> >> "GRANT xxx ON FOREIGN SERVER yyy <tab>" should suggest "TO"?
> >> >> "GRANT xxx ON FOREIGN SERVER yyy TO <tab>" should suggest the roles?
> >> >
> >> >
> >> > Thanks. New version attached that handles these to.
> >>
> >> Thanks for updating the patch!
> >> Attached is the updated version of the patch. Could you review this?
> >
> >
> > Thanks for the review and the improvements!
>
> So applied. Thanks a lot!
>
Since this commit, "grant update on foobar to " will tab complete to add an
extra "TO", rather than with a list of roles.
Cheers,
Jeff
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-09-29 19:59 Thomas Munro <thomas.munro@enterprisedb.com>
parent: Jeff Janes <jeff.janes@gmail.com>
0 siblings, 1 reply; 19+ messages in thread
From: Thomas Munro @ 2015-09-29 19:59 UTC (permalink / raw)
To: Jeff Janes <jeff.janes@gmail.com>; +Cc: Fujii Masao <masao.fujii@gmail.com>; Michael Paquier <michael.paquier@gmail.com>; Josh Berkus <josh@agliodbs.com>; pgsql-bugs
On Wed, Sep 30, 2015 at 5:59 AM, Jeff Janes <jeff.janes@gmail.com> wrote:
> Since this commit, "grant update on foobar to " will tab complete to add an
> extra "TO", rather than with a list of roles.
Oops, thanks. Here is a patch to fix that by moving the branch that
matches "GRANT/REVOKE * ON * *" after the branch that matches
"GRANT/REVOKE ... TO/FROM".
--
Thomas Munro
http://www.enterprisedb.com
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
tab-complete-fix-grant.patch (application/octet-stream, 1.3K) download
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 0cb3464..4294ffd 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3227,15 +3227,6 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_CONST("FROM");
}
- /* Complete "GRANT/REVOKE * ON * *" with TO/FROM */
- else if (pg_strcasecmp(prev5_wd, "GRANT") == 0 &&
- pg_strcasecmp(prev3_wd, "ON") == 0)
- COMPLETE_WITH_CONST("TO");
-
- else if (pg_strcasecmp(prev5_wd, "REVOKE") == 0 &&
- pg_strcasecmp(prev3_wd, "ON") == 0)
- COMPLETE_WITH_CONST("FROM");
-
/* Complete "GRANT/REVOKE * ON ALL * IN SCHEMA *" with TO/FROM */
else if ((pg_strcasecmp(prev8_wd, "GRANT") == 0 ||
pg_strcasecmp(prev8_wd, "REVOKE") == 0) &&
@@ -3295,6 +3286,15 @@ psql_completion(const char *text, int start, int end)
pg_strcasecmp(prev_wd, "FROM") == 0))
COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+ /* Complete "GRANT/REVOKE * ON * *" with TO/FROM */
+ else if (pg_strcasecmp(prev5_wd, "GRANT") == 0 &&
+ pg_strcasecmp(prev3_wd, "ON") == 0)
+ COMPLETE_WITH_CONST("TO");
+
+ else if (pg_strcasecmp(prev5_wd, "REVOKE") == 0 &&
+ pg_strcasecmp(prev3_wd, "ON") == 0)
+ COMPLETE_WITH_CONST("FROM");
+
/*
* Complete "GRANT/REVOKE * TO/FROM" with username, PUBLIC,
* CURRENT_USER, or SESSION_USER.
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-09-30 17:03 Jeff Janes <jeff.janes@gmail.com>
parent: Thomas Munro <thomas.munro@enterprisedb.com>
0 siblings, 1 reply; 19+ messages in thread
From: Jeff Janes @ 2015-09-30 17:03 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: Fujii Masao <masao.fujii@gmail.com>; Michael Paquier <michael.paquier@gmail.com>; Josh Berkus <josh@agliodbs.com>; pgsql-bugs
On Tue, Sep 29, 2015 at 12:59 PM, Thomas Munro <
thomas.munro@enterprisedb.com> wrote:
> On Wed, Sep 30, 2015 at 5:59 AM, Jeff Janes <jeff.janes@gmail.com> wrote:
> > Since this commit, "grant update on foobar to " will tab complete to add
> an
> > extra "TO", rather than with a list of roles.
>
> Oops, thanks. Here is a patch to fix that by moving the branch that
> matches "GRANT/REVOKE * ON * *" after the branch that matches
> "GRANT/REVOKE ... TO/FROM".
>
>
Looks good to me, thanks.
Jeff
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-10-01 14:40 Fujii Masao <masao.fujii@gmail.com>
parent: Jeff Janes <jeff.janes@gmail.com>
0 siblings, 1 reply; 19+ messages in thread
From: Fujii Masao @ 2015-10-01 14:40 UTC (permalink / raw)
To: Jeff Janes <jeff.janes@gmail.com>; +Cc: Thomas Munro <thomas.munro@enterprisedb.com>; Michael Paquier <michael.paquier@gmail.com>; Josh Berkus <josh@agliodbs.com>; pgsql-bugs
On Thu, Oct 1, 2015 at 2:03 AM, Jeff Janes <jeff.janes@gmail.com> wrote:
> On Tue, Sep 29, 2015 at 12:59 PM, Thomas Munro
> <thomas.munro@enterprisedb.com> wrote:
>>
>> On Wed, Sep 30, 2015 at 5:59 AM, Jeff Janes <jeff.janes@gmail.com> wrote:
>> > Since this commit, "grant update on foobar to " will tab complete to add
>> > an
>> > extra "TO", rather than with a list of roles.
>>
>> Oops, thanks. Here is a patch to fix that by moving the branch that
>> matches "GRANT/REVOKE * ON * *" after the branch that matches
>> "GRANT/REVOKE ... TO/FROM".
>>
>
> Looks good to me, thanks.
Applied. Thanks!
Regards,
--
Fujii Masao
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-10-01 18:48 Josh Berkus <josh@agliodbs.com>
parent: Fujii Masao <masao.fujii@gmail.com>
0 siblings, 1 reply; 19+ messages in thread
From: Josh Berkus @ 2015-10-01 18:48 UTC (permalink / raw)
To: Fujii Masao <masao.fujii@gmail.com>; Jeff Janes <jeff.janes@gmail.com>; +Cc: Thomas Munro <thomas.munro@enterprisedb.com>; Michael Paquier <michael.paquier@gmail.com>; pgsql-bugs
On 10/01/2015 07:40 AM, Fujii Masao wrote:
> On Thu, Oct 1, 2015 at 2:03 AM, Jeff Janes <jeff.janes@gmail.com> wrote:
>> On Tue, Sep 29, 2015 at 12:59 PM, Thomas Munro
>> <thomas.munro@enterprisedb.com> wrote:
>>>
>>> On Wed, Sep 30, 2015 at 5:59 AM, Jeff Janes <jeff.janes@gmail.com> wrote:
>>>> Since this commit, "grant update on foobar to " will tab complete to add
>>>> an
>>>> extra "TO", rather than with a list of roles.
>>>
>>> Oops, thanks. Here is a patch to fix that by moving the branch that
>>> matches "GRANT/REVOKE * ON * *" after the branch that matches
>>> "GRANT/REVOKE ... TO/FROM".
>>>
>>
>> Looks good to me, thanks.
>
> Applied. Thanks!
Wow, I had no idea this was going to be such a difficult fix ...
--
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: GRANT USAGE ON SEQUENCE missing from psql command completion
@ 2015-10-01 19:41 Thomas Munro <thomas.munro@enterprisedb.com>
parent: Josh Berkus <josh@agliodbs.com>
0 siblings, 0 replies; 19+ messages in thread
From: Thomas Munro @ 2015-10-01 19:41 UTC (permalink / raw)
To: Josh Berkus <josh@agliodbs.com>; +Cc: Fujii Masao <masao.fujii@gmail.com>; Jeff Janes <jeff.janes@gmail.com>; Michael Paquier <michael.paquier@gmail.com>; pgsql-bugs
On Fri, Oct 2, 2015 at 7:48 AM, Josh Berkus <josh@agliodbs.com> wrote:
> On 10/01/2015 07:40 AM, Fujii Masao wrote:
>> On Thu, Oct 1, 2015 at 2:03 AM, Jeff Janes <jeff.janes@gmail.com> wrote:
>>> On Tue, Sep 29, 2015 at 12:59 PM, Thomas Munro
>>> <thomas.munro@enterprisedb.com> wrote:
>>>>
>>>> On Wed, Sep 30, 2015 at 5:59 AM, Jeff Janes <jeff.janes@gmail.com> wrote:
>>>>> Since this commit, "grant update on foobar to " will tab complete to add
>>>>> an
>>>>> extra "TO", rather than with a list of roles.
>>>>
>>>> Oops, thanks. Here is a patch to fix that by moving the branch that
>>>> matches "GRANT/REVOKE * ON * *" after the branch that matches
>>>> "GRANT/REVOKE ... TO/FROM".
>>>>
>>>
>>> Looks good to me, thanks.
>>
>> Applied. Thanks!
>
> Wow, I had no idea this was going to be such a difficult fix ...
Well, a 3 line patch for the specific problem you reported was posted
straight away.
The rest of this thread got carried away filling out a bunch of other
GRANT/REVOKE completions! And there are probably more things to do
(for example WITH GRANT OPTION).
FWIW I am hoping to make it a bit less cumbersome to maintain the
completion code in the next CF:
https://commitfest.postgresql.org/7/375/
--
Thomas Munro
http://www.enterprisedb.com
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 19+ messages in thread
end of thread, other threads:[~2015-10-01 19:41 UTC | newest]
Thread overview: 19+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-08-20 02:54 GRANT USAGE ON SEQUENCE missing from psql command completion Josh Berkus <josh@agliodbs.com>
2015-08-20 03:10 ` Thomas Munro <thomas.munro@enterprisedb.com>
2015-08-20 03:20 ` Michael Paquier <michael.paquier@gmail.com>
2015-09-01 02:42 ` Thomas Munro <thomas.munro@enterprisedb.com>
2015-09-01 04:24 ` Michael Paquier <michael.paquier@gmail.com>
2015-09-01 13:15 ` Thomas Munro <thomas.munro@enterprisedb.com>
2015-09-02 01:14 ` Michael Paquier <michael.paquier@gmail.com>
2015-09-03 12:02 ` Fujii Masao <masao.fujii@gmail.com>
2015-09-03 22:24 ` Thomas Munro <thomas.munro@enterprisedb.com>
2015-09-04 08:16 ` Fujii Masao <masao.fujii@gmail.com>
2015-09-05 12:43 ` Thomas Munro <thomas.munro@enterprisedb.com>
2015-09-08 17:02 ` Fujii Masao <masao.fujii@gmail.com>
2015-09-29 16:59 ` Jeff Janes <jeff.janes@gmail.com>
2015-09-29 19:59 ` Thomas Munro <thomas.munro@enterprisedb.com>
2015-09-30 17:03 ` Jeff Janes <jeff.janes@gmail.com>
2015-10-01 14:40 ` Fujii Masao <masao.fujii@gmail.com>
2015-10-01 18:48 ` Josh Berkus <josh@agliodbs.com>
2015-10-01 19:41 ` Thomas Munro <thomas.munro@enterprisedb.com>
2015-08-20 03:22 ` Josh Berkus <josh@agliodbs.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox