proposal: psql: show current user in prompt

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: proposal: psql: show current user in prompt
Date: 2023-02-03 14:56:06
Message-ID: CAFj8pRBFU-WzzQhNrwRHn67N0Ug8a9-0-9BOo69PPtcHiBDQMA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

one visitor of p2d2 (Prague PostgreSQL Developer Day) asked if it is
possible to show the current role in psql's prompt. I think it is not
possible, but fortunately (with some limits) almost all necessary work is
done, and the patch is short.

In the assigned patch I implemented a new prompt placeholder %N, that shows
the current role name.

(2023-02-03 15:52:28) postgres=# \set PROMPT1 '%n as %N at '%/%=%#
pavel as pavel at postgres=#set role to admin;
SET
pavel as admin at postgres=>set role to default;
SET
pavel as pavel at postgres=#

Comments, notes are welcome.

Regards

Pavel

Attachment Content-Type Size
0002-implementation-of-psql-prompt-placeholder-N.patch text/x-patch 2.7 KB
0001-implementation-of-BACKEND_PID-psql-s-variable.patch text/x-patch 1.5 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Laurenz Albe 2023-02-03 16:14:29 Re: Make EXPLAIN generate a generic plan for a parameterized query
Previous Message Tom Lane 2023-02-03 14:44:43 Re: Make EXPLAIN generate a generic plan for a parameterized query