Re: [PATCH] psql: tab completion for ALTER ROLE ... IN DATABASE ... - Mailing list pgsql-hackers

From VASUKI M
Subject Re: [PATCH] psql: tab completion for ALTER ROLE ... IN DATABASE ...
Date
Msg-id CAE2r8H79Auaji=HA8K20LQRJp6rXrpvzxnS-bkkk6kd9n9UHUg@mail.gmail.com
Whole thread Raw
In response to [PATCH] psql: tab completion for ALTER ROLE ... IN DATABASE ...  (Ian Lawrence Barwick <barwick@gmail.com>)
List pgsql-hackers

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

Attachment

pgsql-hackers by date:

Previous
From: Mahendra Singh Thalor
Date:
Subject: Re: Non-text mode for pg_dumpall
Next
From: Miłosz Bieniek
Date:
Subject: [PATCH] Add `headerscheck` run_target to meson