Re: Customize psql prompt to show current_role

From: Dominique Devienne <ddevienne(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Wienhold <ewie(at)ewie(dot)name>, Asad Ali <asadalinagri(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Customize psql prompt to show current_role
Date: 2024-09-23 13:08:47
Message-ID: CAFCRh-_BR4QKqTy4AnoTgGE+AiYjAsE1BJ9KPmxU-5vNQ0h+8Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Sep 23, 2024 at 3:05 PM Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> wrote:
> On Mon, 2024-09-23 at 14:59 +0200, Dominique Devienne wrote:
> > On Mon, Sep 23, 2024 at 2:51 PM Erik Wienhold <ewie(at)ewie(dot)name> wrote:
> > > You could instead use this:
> > >
> > > SELECT current_role \gset
> > > \set PROMPT1 '%n(at)%/ (%:current_role:)=%# '
> > >
> > > But that won't work with subsequent SET ROLE commands.
> >
> > Bummer... That was kinda the point, that it updates automatically.
> >
> > Then I'd like to respectfully request a small enhancement to psql
> > to support a new \r (or some other letter) for current_role in the prompt.
>
> To get the current role, psql would have to query the database whenever
> it displays the prompt. That would be rather expensive...

Hi Laurenz. Sure, although expensive might be a bit strong a word.
But that would be opt-in anyway, so just a small warning in the doc
about that new option would suffice, no? --DD

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2024-09-23 14:54:55 Re: Customize psql prompt to show current_role
Previous Message Laurenz Albe 2024-09-23 13:05:10 Re: Customize psql prompt to show current_role