Thread

Commits

  1. Add tab completion for CREATE SCHEMA in psql

  2. psql: improve tab-complete's handling of variant SQL names.

  1. Tab completion for CREATE SCHEMAAUTHORIZATION

    Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> — 2021-07-09T16:20:04Z

    Hi Hackers,
    
    I just noticed there's no tab completion for CREATE SCHEMA
    AUTHORIZATION, nor for anything after CREATE SCHEMA <name>.
    
    Please find attached a patch that adds this.
    
    - ilmari
    
    
  2. Re: Tab completion for CREATE SCHEMAAUTHORIZATION

    Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> — 2021-07-15T11:13:46Z

    ilmari@ilmari.org (Dagfinn Ilmari Mannsåker) writes:
    
    > Hi Hackers,
    >
    > I just noticed there's no tab completion for CREATE SCHEMA
    > AUTHORIZATION, nor for anything after CREATE SCHEMA <name>.
    >
    > Please find attached a patch that adds this.
    
    Added to the 2021-09 commit fest: https://commitfest.postgresql.org/34/3252/
    
    - ilmari
    
    
    
    
  3. Re: Tab completion for CREATE SCHEMAAUTHORIZATION

    Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> — 2021-08-07T21:09:19Z

    ilmari@ilmari.org (Dagfinn Ilmari Mannsåker) writes:
    
    > ilmari@ilmari.org (Dagfinn Ilmari Mannsåker) writes:
    >
    >> Hi Hackers,
    >>
    >> I just noticed there's no tab completion for CREATE SCHEMA
    >> AUTHORIZATION, nor for anything after CREATE SCHEMA <name>.
    >>
    >> Please find attached a patch that adds this.
    >
    > Added to the 2021-09 commit fest: https://commitfest.postgresql.org/34/3252/
    
    Here's an updated version that also reduces the duplication between the
    various role list queries.
    
    - ilmari
    
    
  4. Re: Tab completion for CREATE SCHEMAAUTHORIZATION

    Suraj Khamkar <khamkarsuraj.b@gmail.com> — 2021-08-09T09:23:31Z

    Hello Dagfinn,
    
    I had a look at your patch and below are my review comments.
    Please correct me if I am missing something.
    
       1. For me the patch does not apply cleanly. I have been facing the error
       of trailing whitespaces.
       surajkhamkar@localhost:postgres$ git apply
       v2-0001-Add-tab-completion-for-CREATE-SCHEMA.patch
       v2-0001-Add-tab-completion-for-CREATE-SCHEMA.patch:25: trailing
       whitespace.
       #define Query_for_list_of_schema_roles \
       v2-0001-Add-tab-completion-for-CREATE-SCHEMA.patch:26: trailing
       whitespace.
       Query_for_list_of_roles \
       v2-0001-Add-tab-completion-for-CREATE-SCHEMA.patch:30: trailing
       whitespace.
       #define Query_for_list_of_grant_roles \
       v2-0001-Add-tab-completion-for-CREATE-SCHEMA.patch:31: trailing
       whitespace.
       Query_for_list_of_schema_roles \
       v2-0001-Add-tab-completion-for-CREATE-SCHEMA.patch:32: trailing
       whitespace.
       " UNION ALL SELECT 'PUBLIC'"\
       error: patch failed: src/bin/psql/tab-complete.c:758
       error: src/bin/psql/tab-complete.c: patch does not apply
    
       2. We can remove space in before \ and below change
       +" UNION ALL SELECT 'PUBLIC'" \
    
       Should be,
       +" UNION ALL SELECT 'PUBLIC' "\
    
       3. role_specification has CURRENT_ROLE, CURRENT_USER and SESSION_USER.
       But current changes are missing CURRENT_ROLE.
       postgres@53724=#CREATE SCHEMA AUTHORIZATION
       CURRENT_USER               pg_execute_server_program  pg_read_all_data
    
       pg_read_all_stats          pg_signal_backend          pg_write_all_data
    
       SESSION_USER               pg_database_owner          pg_monitor
    
       pg_read_all_settings       pg_read_server_files
       pg_stat_scan_tables
       pg_write_server_files      surajkhamkar
    
       4. I'm not sure about this but do we need to enable tab completion for IF
       NOT EXIST?
    
       5. I think we are not handling IF NOT EXIST that's why it's not
       completing tab completion
       for AUTHORIZATION.
    
       6. As we are here we can also enable missing tab completion for ALTER
       SCHEMA.
       After OWNER TO we should also get CURRENT_ROLE, CURRENT_USER and
       SESSION_USER.
       postgres@53724=#ALTER SCHEMA sch owner to
       pg_database_owner          pg_monitor
       pg_read_all_settings
       pg_read_server_files       pg_stat_scan_tables
        pg_write_server_files
       pg_execute_server_program  pg_read_all_data           pg_read_all_stats
    
       pg_signal_backend          pg_write_all_data          surajkhamkar
    
       7. Similarly, as we can drop multiple schemas' simultaneously, we should
       enable tab completion for
       comma with CASCADE and RESTRICT
       postgres@53724=#DROP SCHEMA sch
       CASCADE   RESTRICT
    
    
    Thanks.
    
    On Sun, Aug 8, 2021 at 2:39 AM Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
    wrote:
    
    > ilmari@ilmari.org (Dagfinn Ilmari Mannsåker) writes:
    >
    > > ilmari@ilmari.org (Dagfinn Ilmari Mannsåker) writes:
    > >
    > >> Hi Hackers,
    > >>
    > >> I just noticed there's no tab completion for CREATE SCHEMA
    > >> AUTHORIZATION, nor for anything after CREATE SCHEMA <name>.
    > >>
    > >> Please find attached a patch that adds this.
    > >
    > > Added to the 2021-09 commit fest:
    > https://commitfest.postgresql.org/34/3252/
    >
    > Here's an updated version that also reduces the duplication between the
    > various role list queries.
    >
    > - ilmari
    >
    >
    
  5. Re: Tab completion for CREATE SCHEMAAUTHORIZATION

    Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> — 2021-08-09T18:00:02Z

    Hi Suraj,
    
    Suraj Khamkar <khamkarsuraj.b@gmail.com> writes:
    
    > Hello Dagfinn,
    >
    > I had a look at your patch and below are my review comments.
    > Please correct me if I am missing something.
    >
    >    1. For me the patch does not apply cleanly. I have been facing the error
    >    of trailing whitespaces.
    
    I do not get these errors, neither with the patch file I still have
    locally, or by saving the attachment from my original email.  Are you
    sure something in your download process hasn't converted it to Windows
    line endings (\r\n), or otherwise mangled the whitespace?
    
    >    2. We can remove space in before \ and below change
    >    +" UNION ALL SELECT 'PUBLIC'" \
    >
    >    Should be,
    >    +" UNION ALL SELECT 'PUBLIC' "\
    
    The patch doesn't add any lines that end with quote-space-backslash.
    As for the space before the quote, that is not necessary either, since the
    next line starts with a space after the quote.  Either way, the updated
    version of the patch doesn't add any new lines with continuation after a
    string constant, so the point is moot.
    
    >    3. role_specification has CURRENT_ROLE, CURRENT_USER and SESSION_USER.
    >    But current changes are missing CURRENT_ROLE.
    
    Ah, I was looking at the documentation for 13, but CURRENT_ROLE is only
    allowed in this context as of 14.  Fixed.
    
    >    4. I'm not sure about this but do we need to enable tab completion for IF
    >    NOT EXIST?
    >
    >    5. I think we are not handling IF NOT EXIST that's why it's not
    >    completing tab completion
    >    for AUTHORIZATION.
    
    As you note, psql currently doesn't currently tab-complete IF NOT EXISTS
    for any command, so that would be a subject for a separate patch.
    
    >    6. As we are here we can also enable missing tab completion for ALTER
    >    SCHEMA.
    >    After OWNER TO we should also get CURRENT_ROLE, CURRENT_USER and
    >    SESSION_USER.
    
    I did an audit of all the uses of Query_for_list_of_roles, and there
    turned out be several more that accept CURRENT_ROLE, CURRENT_USER and
    SESSION_USER that they weren't tab-completed for.  I also renamed the
    constant to Query_for_list_of_owner_roles, but I'm not 100% happy with
    that name either.
    
    >    7. Similarly, as we can drop multiple schemas' simultaneously, we should
    >    enable tab completion for
    >    comma with CASCADE and RESTRICT
    >    postgres@53724=#DROP SCHEMA sch
    >    CASCADE   RESTRICT
    
    The tab completion code for DROP is generic for all object types (see
    the words_after_create array and the create_or_drop_command_generator
    function), so that should be done genericallly, and is thus outside the
    scope for this patch.
    
    > Thanks.
    
    Thanks for the review.  Updated patch attached, with the CURRENT/SESSION
    ROLE/USER changes for other commands separated out.
    
    - ilmari
    
    
  6. Re: Tab completion for CREATE SCHEMAAUTHORIZATION

    Michael Paquier <michael@paquier.xyz> — 2021-08-11T01:16:15Z

    On Mon, Aug 09, 2021 at 07:00:02PM +0100, Dagfinn Ilmari Mannsåker wrote:
    > Thanks for the review.  Updated patch attached, with the CURRENT/SESSION
    > ROLE/USER changes for other commands separated out.
    
    +#define Query_for_list_of_owner_roles \
    +Query_for_list_of_roles \
     " UNION ALL SELECT 'CURRENT_ROLE'"\
     " UNION ALL SELECT 'CURRENT_USER'"\
     " UNION ALL SELECT 'SESSION_USER'"
    I don't object to the refactoring you are doing here with three
    Query_for_list_of_*_roles each one depending on the other for clarity.
    Neither do I really object to not using COMPLETE_WITH_QUERY() with
    some extra UNION ALL hardcoded in each code path as there 6 cases for
    _owner_, 6 for _grant_ and 6 for _roles if my count is right.  Still,
    if I may ask, wouldn't it be better to document a bit what's the
    expectation behind each one of them?  Perhaps the names of the queries
    are too generic for the purposes where they are used (say _grant_ for
    CREATE USER MAPPING looks confusing)?
    
    +       else if (Matches("CREATE", "SCHEMA", "AUTHORIZATION"))
    +               COMPLETE_WITH_QUERY(Query_for_list_of_owner_roles);
    +       else if (Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION"))
    +               COMPLETE_WITH_QUERY(Query_for_list_of_owner_roles);
    +       else if (Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION", MatchAny))
    +               COMPLETE_WITH("CREATE", "GRANT");
    +       else if (Matches("CREATE", "SCHEMA", MatchAny))
    +               COMPLETE_WITH("AUTHORIZATION", "CREATE", "GRANT");
    Looks like you forgot the case "CREATE SCHEMA AUTHORIZATION MatchAny"
    that should be completed by GRANT and CREATE.
    --
    Michael
    
  7. Re: Tab completion for CREATE SCHEMAAUTHORIZATION

    Suraj Khamkar <khamkarsuraj.b@gmail.com> — 2021-08-11T17:34:10Z

    Thanks Dagfinn for the updated patches.
    
    I do not get these errors, neither with the patch file I still have
    > locally, or by saving the attachment from my original email.  Are you
    > sure something in your download process hasn't converted it to Windows
    > line endings (\r\n), or otherwise mangled the whitespace?
    
    
    No. I have downloaded patch on linux and patch also doesn't have any
    trailing
    spaces, though it is throwing an error.
    
    Here are few other comments,
    
       1. USER MAPPING does not have SESSION_USER as username in syntax
       (though it works) but your changes provide the same. Also, we have USER
        in
       list which is missing in current code changes.
       CREATE USER MAPPING [ IF NOT EXISTS ] FOR { user_name | USER |
       CURRENT_ROLE | CURRENT_USER | PUBLIC }
           SERVER server_name
           [ OPTIONS ( option 'value' [ , ... ] ) ]
       2. It might not be a scope of this ticket but as we are changing the
       query for ALTER GROUP,
       we should complete the role_specification after ALTER GROUP.
       postgres@17077=#ALTER GROUP
       pg_database_owner          pg_monitor
       pg_read_all_settings
       pg_read_server_files       pg_stat_scan_tables
        pg_write_server_files
       surajkhamkar.              pg_execute_server_program  pg_read_all_data
    
       pg_read_all_stats          pg_signal_backend          pg_write_all_data
    
       3. Missing schema_elements after CREATE SCHEMA AUTHORIZATION username to
       tab-complete .
       schema_elements might be CREATE, GRAND etc.
    
    
    Thanks..
    
    On Mon, Aug 9, 2021 at 11:30 PM Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
    wrote:
    
    > Hi Suraj,
    >
    > Suraj Khamkar <khamkarsuraj.b@gmail.com> writes:
    >
    > > Hello Dagfinn,
    > >
    > > I had a look at your patch and below are my review comments.
    > > Please correct me if I am missing something.
    > >
    > >    1. For me the patch does not apply cleanly. I have been facing the
    > error
    > >    of trailing whitespaces.
    >
    > I do not get these errors, neither with the patch file I still have
    > locally, or by saving the attachment from my original email.  Are you
    > sure something in your download process hasn't converted it to Windows
    > line endings (\r\n), or otherwise mangled the whitespace?
    >
    > >    2. We can remove space in before \ and below change
    > >    +" UNION ALL SELECT 'PUBLIC'" \
    > >
    > >    Should be,
    > >    +" UNION ALL SELECT 'PUBLIC' "\
    >
    > The patch doesn't add any lines that end with quote-space-backslash.
    > As for the space before the quote, that is not necessary either, since the
    > next line starts with a space after the quote.  Either way, the updated
    > version of the patch doesn't add any new lines with continuation after a
    > string constant, so the point is moot.
    >
    > >    3. role_specification has CURRENT_ROLE, CURRENT_USER and SESSION_USER.
    > >    But current changes are missing CURRENT_ROLE.
    >
    > Ah, I was looking at the documentation for 13, but CURRENT_ROLE is only
    > allowed in this context as of 14.  Fixed.
    >
    > >    4. I'm not sure about this but do we need to enable tab completion
    > for IF
    > >    NOT EXIST?
    > >
    > >    5. I think we are not handling IF NOT EXIST that's why it's not
    > >    completing tab completion
    > >    for AUTHORIZATION.
    >
    > As you note, psql currently doesn't currently tab-complete IF NOT EXISTS
    > for any command, so that would be a subject for a separate patch.
    >
    > >    6. As we are here we can also enable missing tab completion for ALTER
    > >    SCHEMA.
    > >    After OWNER TO we should also get CURRENT_ROLE, CURRENT_USER and
    > >    SESSION_USER.
    >
    > I did an audit of all the uses of Query_for_list_of_roles, and there
    > turned out be several more that accept CURRENT_ROLE, CURRENT_USER and
    > SESSION_USER that they weren't tab-completed for.  I also renamed the
    > constant to Query_for_list_of_owner_roles, but I'm not 100% happy with
    > that name either.
    >
    > >    7. Similarly, as we can drop multiple schemas' simultaneously, we
    > should
    > >    enable tab completion for
    > >    comma with CASCADE and RESTRICT
    > >    postgres@53724=#DROP SCHEMA sch
    > >    CASCADE   RESTRICT
    >
    > The tab completion code for DROP is generic for all object types (see
    > the words_after_create array and the create_or_drop_command_generator
    > function), so that should be done genericallly, and is thus outside the
    > scope for this patch.
    >
    > > Thanks.
    >
    > Thanks for the review.  Updated patch attached, with the CURRENT/SESSION
    > ROLE/USER changes for other commands separated out.
    >
    > - ilmari
    >
    >
    
  8. Re: Tab completion for CREATE SCHEMAAUTHORIZATION

    Michael Paquier <michael@paquier.xyz> — 2021-12-03T01:19:23Z

    On Wed, Aug 11, 2021 at 10:16:15AM +0900, Michael Paquier wrote:
    > +       else if (Matches("CREATE", "SCHEMA", "AUTHORIZATION"))
    > +               COMPLETE_WITH_QUERY(Query_for_list_of_owner_roles);
    > +       else if (Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION"))
    > +               COMPLETE_WITH_QUERY(Query_for_list_of_owner_roles);
    > +       else if (Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION", MatchAny))
    > +               COMPLETE_WITH("CREATE", "GRANT");
    > +       else if (Matches("CREATE", "SCHEMA", MatchAny))
    > +               COMPLETE_WITH("AUTHORIZATION", "CREATE", "GRANT");
    > Looks like you forgot the case "CREATE SCHEMA AUTHORIZATION MatchAny"
    > that should be completed by GRANT and CREATE.
    
    This patch has been waiting on author for more than a couple of weeks,
    so I have marked it as returned with feedback in the CF app.  Please
    feel free to resubmit if you are able to work more on that.
    --
    Michael
    
  9. Re: Tab completion for CREATE SCHEMAAUTHORIZATION

    Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> — 2023-04-14T16:04:35Z

    Michael Paquier <michael@paquier.xyz> writes:
    
    > On Wed, Aug 11, 2021 at 10:16:15AM +0900, Michael Paquier wrote:
    >> +       else if (Matches("CREATE", "SCHEMA", "AUTHORIZATION"))
    >> +               COMPLETE_WITH_QUERY(Query_for_list_of_owner_roles);
    >> +       else if (Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION"))
    >> +               COMPLETE_WITH_QUERY(Query_for_list_of_owner_roles);
    >> +       else if (Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION", MatchAny))
    >> +               COMPLETE_WITH("CREATE", "GRANT");
    >> +       else if (Matches("CREATE", "SCHEMA", MatchAny))
    >> +               COMPLETE_WITH("AUTHORIZATION", "CREATE", "GRANT");
    >> Looks like you forgot the case "CREATE SCHEMA AUTHORIZATION MatchAny"
    >> that should be completed by GRANT and CREATE.
    >
    > This patch has been waiting on author for more than a couple of weeks,
    > so I have marked it as returned with feedback in the CF app.  Please
    > feel free to resubmit if you are able to work more on that.
    
    Looks like I completely dropped the ball on this one, sorry.  Here's a
    rebased patch which uses the new COMPLETE_WITH_QUERY_PLUS functionality
    added in commit 02b8048ba5dc36238f3e7c3c58c5946220298d71.
    
    
    - ilmari
    
    
    
  10. Re: Tab completion for CREATE SCHEMAAUTHORIZATION

    Michael Paquier <michael@paquier.xyz> — 2023-04-15T02:06:25Z

    On Fri, Apr 14, 2023 at 05:04:35PM +0100, Dagfinn Ilmari Mannsåker wrote:
    > Looks like I completely dropped the ball on this one, sorry.
    
    So did I ;)
    
    > Here's a
    > rebased patch which uses the new COMPLETE_WITH_QUERY_PLUS functionality
    > added in commit 02b8048ba5dc36238f3e7c3c58c5946220298d71.
    
    Thanks, I'll look at it.
    --
    Michael
    
  11. Re: Tab completion for CREATE SCHEMAAUTHORIZATION

    Michael Paquier <michael@paquier.xyz> — 2023-05-02T02:09:59Z

    On Sat, Apr 15, 2023 at 11:06:25AM +0900, Michael Paquier wrote:
    > Thanks, I'll look at it.
    
    +   else if (Matches("CREATE", "SCHEMA", "AUTHORIZATION", MatchAny) ||
    +            Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION", MatchAny))
    +       COMPLETE_WITH("CREATE", "GRANT");
    +   else if (Matches("CREATE", "SCHEMA", MatchAny))
    +       COMPLETE_WITH("AUTHORIZATION", "CREATE", "GRANT");
    
    I had this grammar under my eyes a few days ago for a different patch,
    and there are much more objects types that can be appended to a CREATE
    SCHEMA, like triggers, sequences, tables or views, so this is
    incomplete, isn't it?
    --
    Michael
    
  12. Re: Tab completion for CREATE SCHEMAAUTHORIZATION

    Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> — 2023-05-02T10:48:43Z

    Michael Paquier <michael@paquier.xyz> writes:
    
    > On Sat, Apr 15, 2023 at 11:06:25AM +0900, Michael Paquier wrote:
    >> Thanks, I'll look at it.
    >
    > +   else if (Matches("CREATE", "SCHEMA", "AUTHORIZATION", MatchAny) ||
    > +            Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION", MatchAny))
    > +       COMPLETE_WITH("CREATE", "GRANT");
    > +   else if (Matches("CREATE", "SCHEMA", MatchAny))
    > +       COMPLETE_WITH("AUTHORIZATION", "CREATE", "GRANT");
    >
    > I had this grammar under my eyes a few days ago for a different patch,
    > and there are much more objects types that can be appended to a CREATE
    > SCHEMA, like triggers, sequences, tables or views, so this is
    > incomplete, isn't it?
    
    This is for completing the word CREATE itself after CREATE SCHEMA
    [[<name>] AUTHORIZATION] <name>.  The things that can come after that
    are already handled generically earlier in the function:
    
    /* CREATE */
        /* complete with something you can create */
        else if (TailMatches("CREATE"))
            matches = rl_completion_matches(text, create_command_generator);
    
    create_command_generator uses the words_after_create array, which lists
    all the things that can be created.
    
    - ilmari
    
    
    
    
  13. Re: Tab completion for CREATE SCHEMAAUTHORIZATION

    Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> — 2023-05-02T12:19:49Z

    Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> writes:
    
    > Michael Paquier <michael@paquier.xyz> writes:
    >
    >> On Sat, Apr 15, 2023 at 11:06:25AM +0900, Michael Paquier wrote:
    >>> Thanks, I'll look at it.
    >>
    >> +   else if (Matches("CREATE", "SCHEMA", "AUTHORIZATION", MatchAny) ||
    >> +            Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION", MatchAny))
    >> +       COMPLETE_WITH("CREATE", "GRANT");
    >> +   else if (Matches("CREATE", "SCHEMA", MatchAny))
    >> +       COMPLETE_WITH("AUTHORIZATION", "CREATE", "GRANT");
    >>
    >> I had this grammar under my eyes a few days ago for a different patch,
    >> and there are much more objects types that can be appended to a CREATE
    >> SCHEMA, like triggers, sequences, tables or views, so this is
    >> incomplete, isn't it?
    >
    > This is for completing the word CREATE itself after CREATE SCHEMA
    > [[<name>] AUTHORIZATION] <name>.  The things that can come after that
    > are already handled generically earlier in the function:
    >
    > /* CREATE */
    >     /* complete with something you can create */
    >     else if (TailMatches("CREATE"))
    >         matches = rl_completion_matches(text, create_command_generator);
    >
    > create_command_generator uses the words_after_create array, which lists
    > all the things that can be created.
    
    But, looking closer at the docs, only tables, views, indexes, sequences
    and triggers can be created as part of a CREATE SCHEMA statement. Maybe
    we should add a HeadMatches("CREATE", "SCHEMA") exception in the above?
    
    - ilmari
    
    
    
    
  14. Re: Tab completion for CREATE SCHEMAAUTHORIZATION

    Michael Paquier <michael@paquier.xyz> — 2023-05-06T02:58:43Z

    On Tue, May 02, 2023 at 01:19:49PM +0100, Dagfinn Ilmari Mannsåker wrote:
    > Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> writes:
    >> This is for completing the word CREATE itself after CREATE SCHEMA
    >> [[<name>] AUTHORIZATION] <name>.  The things that can come after that
    >> are already handled generically earlier in the function:
    >>
    >> /* CREATE */
    >>     /* complete with something you can create */
    >>     else if (TailMatches("CREATE"))
    >>         matches = rl_completion_matches(text, create_command_generator);
    >>
    >> create_command_generator uses the words_after_create array, which lists
    >> all the things that can be created.
    
    You are right.  I have completely forgotten that this code path would
    append everything that supports CREATE for a CREATE SCHEMA command :)
    
    > But, looking closer at the docs, only tables, views, indexes, sequences
    > and triggers can be created as part of a CREATE SCHEMA statement. Maybe
    > we should add a HeadMatches("CREATE", "SCHEMA") exception in the above?
    
    Yes, it looks like we are going to need an exception and append only
    the keywords that are supported, or we will end up recommending mostly
    things that are not accepted by the parser.
    --
    Michael
    
  15. Re: Tab completion for CREATE SCHEMAAUTHORIZATION

    Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> — 2023-05-08T16:36:27Z

    Michael Paquier <michael@paquier.xyz> writes:
    
    > On Tue, May 02, 2023 at 01:19:49PM +0100, Dagfinn Ilmari Mannsåker wrote:
    >> Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> writes:
    >>> This is for completing the word CREATE itself after CREATE SCHEMA
    >>> [[<name>] AUTHORIZATION] <name>.  The things that can come after that
    >>> are already handled generically earlier in the function:
    >>>
    >>> /* CREATE */
    >>>     /* complete with something you can create */
    >>>     else if (TailMatches("CREATE"))
    >>>         matches = rl_completion_matches(text, create_command_generator);
    >>>
    >>> create_command_generator uses the words_after_create array, which lists
    >>> all the things that can be created.
    >
    > You are right.  I have completely forgotten that this code path would
    > append everything that supports CREATE for a CREATE SCHEMA command :)
    >
    >> But, looking closer at the docs, only tables, views, indexes, sequences
    >> and triggers can be created as part of a CREATE SCHEMA statement. Maybe
    >> we should add a HeadMatches("CREATE", "SCHEMA") exception in the above?
    >
    > Yes, it looks like we are going to need an exception and append only
    > the keywords that are supported, or we will end up recommending mostly
    > things that are not accepted by the parser.
    
    Here's an updated v3 patch with that.  While adding that, I noticed that
    CREATE UNLOGGED only tab-completes TABLE and MATERIALIZED VIEW, not
    SEQUENCE, so I added that (and removed MATERIALIZED VIEW when part of
    CREATE SCHEMA).
    
    - ilmari
    
    
  16. Re: Tab completion for CREATE SCHEMAAUTHORIZATION

    Michael Paquier <michael@paquier.xyz> — 2023-05-09T03:26:16Z

    On Mon, May 08, 2023 at 05:36:27PM +0100, Dagfinn Ilmari Mannsåker wrote:
    > Here's an updated v3 patch with that.  While adding that, I noticed that
    > CREATE UNLOGGED only tab-completes TABLE and MATERIALIZED VIEW, not
    > SEQUENCE, so I added that (and removed MATERIALIZED VIEW when part of
    > CREATE SCHEMA).
    
    +       /* but not MATVIEW in CREATE SCHEMA */
    +       if (HeadMatches("CREATE", "SCHEMA"))
    +           COMPLETE_WITH("TABLE", "SEQUENCE");
    +       else
    +           COMPLETE_WITH("TABLE", "SEQUENCE", "MATERIALIZED VIEW");
    
    This may look strange at first glance, but the grammar is what it
    is..  Perhaps matviews could be part of that at some point.  Or not. :)
    
    +       /* only some object types can be created as part of CREATE SCHEMA */
    +       if (HeadMatches("CREATE", "SCHEMA"))
    +           COMPLETE_WITH("TABLE", "VIEW", "INDEX", "SEQUENCE", "TRIGGER",
    +                         /* for INDEX and TABLE/SEQUENCE, respectively */
    +                         "UNIQUE", "UNLOGGED");
    
    Not including TEMPORARY is OK here as the grammar does not allow a
    directly to create a temporary schema.  The (many) code paths that
    have TailMatches() to cope with CREATE SCHEMA would continue the
    completion of added, but at least this approach avoids the
    recommendation if possible.
    
    That looks pretty much OK to me.  One tiny comment I have is that this
    lacks brackets for the inner blocks, so I have added some in the v4
    attached.
    --
    Michael
    
  17. Re: Tab completion for CREATE SCHEMAAUTHORIZATION

    Michael Paquier <michael@paquier.xyz> — 2023-06-30T01:36:47Z

    On Tue, May 09, 2023 at 12:26:16PM +0900, Michael Paquier wrote:
    > That looks pretty much OK to me.  One tiny comment I have is that this
    > lacks brackets for the inner blocks, so I have added some in the v4
    > attached.
    
    The indentation was a bit wrong, so fixed it, and applied on HEAD.
    --
    Michael
    
  18. Re: Tab completion for CREATE SCHEMAAUTHORIZATION

    Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> — 2023-06-30T09:33:22Z

    Michael Paquier <michael@paquier.xyz> writes:
    
    > On Tue, May 09, 2023 at 12:26:16PM +0900, Michael Paquier wrote:
    >> That looks pretty much OK to me.  One tiny comment I have is that this
    >> lacks brackets for the inner blocks, so I have added some in the v4
    >> attached.
    >
    > The indentation was a bit wrong, so fixed it, and applied on HEAD.
    
    Thanks!
    
    - ilmari