Thread

  1. Re: [PATCH] psql: tab completion for ALTER ROLE ... IN DATABASE ...

    VASUKI M <vasukianand0119@gmail.com> — 2025-11-27T09:20:07Z

    Hello all,
    
    Based on the discussion, I have updated the patch to handle the RESET form
    correctly without modifying psql’s tab-completion APIs.
    
    Both the current database connection and the parsed input tokens are
    already available via pset.db and the word tokens.The new patch extracts:
    
       -
    
       the role name from the parsed tokens (prev5_wd), and
       -
    
       the database name from the parsed tokens (prev2_wd),
    
    and uses these to query pg_db_role_setting for variables that are actually
    set for the specific (role, database) pair.
    
    Literal quoting is now done with PQescapeLiteral(pset.db, …), per libpq
    conventions, so no new helper functions were needed.
    
    SET
    After
    
    ALTER ROLE <role> IN DATABASE <dbname> SET <TAB>
    
    psql completes from Query_for_list_of_set_vars (same behavior as plain
    ALTER ROLE … SET).
    
    RESET
    After
    
    ALTER ROLE <role> IN DATABASE <dbname> RESET <TAB>
    
    psql now completes with the GUC names recorded in pg_db_role_setting for
    that specific (role,database), plus ALL.
    When no settings exist, only ALL is suggested.
    This mirrors the existing behavior of ALTER DATABASE … RESET.
    
    I have attached the patch.
    
    Regards,
    
    Vasuki
    
    On Thu, Nov 27, 2025 at 2:27 PM Ian Lawrence Barwick <barwick@gmail.com>
    wrote:
    
    > Hi
    >
    > I found myself needing to work with ALTER ROLE ... IN DATABASE ... recently
    > and was annoyed by the lack of tab completion for this, so patch attached.
    >
    >
    > Regards
    >
    > Ian Barwick
    >
    >