Re: session username in default psql prompt?

2024-04-11 Thread jian he
On Tue, Mar 26, 2024 at 7:14 AM Andrew Dunstan  wrote:
>
>
>
> On Mon, Mar 25, 2024 at 9:14 AM Jelte Fennema-Nio  wrote:
>>
>> On Mon, 25 Mar 2024 at 14:06, Robert Haas  wrote:
>> > On Mon, Mar 25, 2024 at 4:30 AM Jelte Fennema-Nio  
>> > wrote:
>> > > That problem seems easy to address by adding a newline into the
>> > > default prompt.
>> >
>> > Ugh. Please, no!
>>
>> I guess it's partially a matter of taste, but personally I'm never
>> going back to a single line prompt. It's so nice for zoomed-in demos
>> that your SQL queries don't get broken up.
>
>
>
> Very  much a matter of taste. I knew when I saw your suggestion there would 
> be some kickback. If horizontal space is at a premium vertical space is 
> doubly so, I suspect.
>

the change (session username in default psql prompt) is quite visible,
maybe this time we can conduct a poll,
but in a way the poll can reach more people?




Re: session username in default psql prompt?

2024-03-25 Thread Andrew Dunstan
On Mon, Mar 25, 2024 at 9:14 AM Jelte Fennema-Nio 
wrote:

> On Mon, 25 Mar 2024 at 14:06, Robert Haas  wrote:
> > On Mon, Mar 25, 2024 at 4:30 AM Jelte Fennema-Nio 
> wrote:
> > > That problem seems easy to address by adding a newline into the
> > > default prompt.
> >
> > Ugh. Please, no!
>
> I guess it's partially a matter of taste, but personally I'm never
> going back to a single line prompt. It's so nice for zoomed-in demos
> that your SQL queries don't get broken up.
>


Very  much a matter of taste. I knew when I saw your suggestion there would
be some kickback. If horizontal space is at a premium vertical space is
doubly so, I suspect.

cheers

andrew


Re: session username in default psql prompt?

2024-03-25 Thread Jelte Fennema-Nio
On Mon, 25 Mar 2024 at 14:06, Robert Haas  wrote:
> On Mon, Mar 25, 2024 at 4:30 AM Jelte Fennema-Nio  wrote:
> > That problem seems easy to address by adding a newline into the
> > default prompt.
>
> Ugh. Please, no!

I guess it's partially a matter of taste, but personally I'm never
going back to a single line prompt. It's so nice for zoomed-in demos
that your SQL queries don't get broken up.




Re: session username in default psql prompt?

2024-03-25 Thread Robert Haas
On Mon, Mar 25, 2024 at 4:30 AM Jelte Fennema-Nio  wrote:
> That problem seems easy to address by adding a newline into the
> default prompt.

Ugh. Please, no!

-- 
Robert Haas
EDB: http://www.enterprisedb.com




Re: session username in default psql prompt?

2024-03-25 Thread Jelte Fennema-Nio
On Mon, 25 Mar 2024 at 11:40, jian he  wrote:
> transaction related information lost.

Ah yeah, it seems I somehow lost the %x
How about:
\set PROMPT1 '%n@%~\n%R%x%# '

Or maybe even this more verbose one, which closely matches the
postgresql:// connection string format:

\set PROMPT1 '%n@%M:%>/%/\n%R%x%# '

or even add in some bold/colors like this, to make the prompt stand
out from a query:

\set PROMPT1 '%[%033[1m%]%n@%M:%>/%/\n%R%x%#%[%033[0m%] '




Re: session username in default psql prompt?

2024-03-25 Thread jian he
On Mon, Mar 25, 2024 at 6:32 PM Jelte Fennema-Nio  wrote:
>
> Obviously I meant to put the \n before the %:
> \set PROMPT1 '%n@%~%R\n%# '
>

transaction related information lost.

for example:
jian@src6=
# begin;
BEGIN
jian@src6=
# select 1/0;
2024-03-25 18:37:59.313 CST [15252] ERROR:  division by zero
2024-03-25 18:37:59.313 CST [15252] STATEMENT:  select 1/0;
ERROR:  division by zero
jian@src6=
# rollback ;
ROLLBACK


master behavior:
src6=# begin ;
BEGIN
src6=*# select 1/0;
2024-03-25 18:38:31.997 CST [24688] ERROR:  division by zero
2024-03-25 18:38:31.997 CST [24688] STATEMENT:  select 1/0;
ERROR:  division by zero
src6=!# rollback ;
ROLLBACK




Re: session username in default psql prompt?

2024-03-25 Thread Jelte Fennema-Nio
On Mon, 25 Mar 2024 at 09:30, Jelte Fennema-Nio  wrote:
> \set PROMPT1 '%n@%~%R%\n# '

Obviously I meant to put the \n before the %:
\set PROMPT1 '%n@%~%R\n%# '




Re: session username in default psql prompt?

2024-03-25 Thread Jelte Fennema-Nio
On Sat, 23 Mar 2024 at 00:34, Tom Lane  wrote:
> Prompt space is
> expensive and precious, at least for people who aren't in the
> habit of working in very wide windows.

That problem seems easy to address by adding a newline into the
default prompt. Something like this:

\set PROMPT1 '%n@%~%R%\n# '

I myself use:
\set PROMPT1 '%[%033[1m%]%M %n@%/:%>-%p%R%[%033[0m%]%\n> '




Re: session username in default psql prompt?

2024-03-22 Thread Andrew Dunstan
On Fri, Mar 22, 2024 at 7:34 PM Tom Lane  wrote:

>
> On the whole, I think we'd get more complaints about the default
> prompt having more-or-less doubled in length than we'd get kudos
> about this being a great usability improvement.  Prompt space is
> expensive and precious, at least for people who aren't in the
> habit of working in very wide windows.
>
>
>


I'm not sure you're right, but in view of the opposition I won't press it.
Thanks to Kori for the patch.

cheers

andrew


Re: session username in default psql prompt?

2024-03-22 Thread Tom Lane
Andrew Dunstan  writes:
> On Fri, Mar 22, 2024 at 4:04 PM Robert Haas  wrote:
>> I'm not really a fan of this. Right now my prompt looks like this:
>> robert.haas=#
>> If we did this, it would say:
>> robert.h...@robert.haas=#

There would be similar duplication for, eg, the postgres user
connected to the postgres database.  However, I'm more worried
about the case where they don't match, because then the %~
suggestion doesn't help shorten it.

> Of course, people can put this in their .psqlrc, and I do. The suggestion
> came about because I had a couple of instances where people using the
> default prompt showed me stuff and the problem arose from confusion about
> which user they were connected as.

On the whole, I think we'd get more complaints about the default
prompt having more-or-less doubled in length than we'd get kudos
about this being a great usability improvement.  Prompt space is
expensive and precious, at least for people who aren't in the
habit of working in very wide windows.

regards, tom lane




Re: session username in default psql prompt?

2024-03-22 Thread Andrew Dunstan
On Fri, Mar 22, 2024 at 4:04 PM Robert Haas  wrote:

> On Wed, Mar 13, 2024 at 4:56 AM Andrew Dunstan 
> wrote:
> > Reposting as the archive mail processor doesn't seem to like the Apple
> > mail attachment.
>
> I'm not really a fan of this. Right now my prompt looks like this:
>
> robert.haas=#
>
> If we did this, it would say:
>
> robert.h...@robert.haas=#
>



Hmm. Perhaps we should change the default to "%n@%~%R%x%# "

Then when connected to your eponymous database you would see

robert.haas@~=#

Of course, people can put this in their .psqlrc, and I do. The suggestion
came about because I had a couple of instances where people using the
default prompt showed me stuff and the problem arose from confusion about
which user they were connected as.



> I have yet to meet anyone who doesn't think that one Robert Haas is
> quite enough already, and perhaps too much by half.
>



perish the thought.

cheers

andrew


Re: session username in default psql prompt?

2024-03-22 Thread Robert Haas
On Wed, Mar 13, 2024 at 4:56 AM Andrew Dunstan  wrote:
> Reposting as the archive mail processor doesn't seem to like the Apple
> mail attachment.

I'm not really a fan of this. Right now my prompt looks like this:

robert.haas=#

If we did this, it would say:

robert.h...@robert.haas=#

I have yet to meet anyone who doesn't think that one Robert Haas is
quite enough already, and perhaps too much by half.

-- 
Robert Haas
EDB: http://www.enterprisedb.com




Re: session username in default psql prompt?

2024-03-13 Thread Andrew Dunstan


On 2024-02-27 Tu 19:19, Kori Lane wrote:

Here’s a patch for this.




Reposting as the archive mail processor doesn't seem to like the Apple 
mail attachment.



cheers


andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index cc7d797159..7e82355425 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -4729,7 +4729,7 @@ testdb= \set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# '
 
 To insert a percent sign into your prompt, write
 %%. The default prompts are
-'%/%R%x%# ' for prompts 1 and 2, and
+'%n@%/%R%x%# ' for prompts 1 and 2, and
 ' ' for prompt 3.
 
 
diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h
index 505f99d8e4..8477f9 100644
--- a/src/bin/psql/settings.h
+++ b/src/bin/psql/settings.h
@@ -23,8 +23,8 @@
 #define DEFAULT_EDITOR_LINENUMBER_ARG "+"
 #endif
 
-#define DEFAULT_PROMPT1 "%/%R%x%# "
-#define DEFAULT_PROMPT2 "%/%R%x%# "
+#define DEFAULT_PROMPT1 "%n@%/%R%x%# "
+#define DEFAULT_PROMPT2 "%n@%/%R%x%# "
 #define DEFAULT_PROMPT3 ">> "
 
 /*


Re: session username in default psql prompt?

2024-02-27 Thread Kori Lane
Here’s a patch for this.- Kori

session-user-prompt.patch
Description: Binary data
On May 27, 2023, at 8:52 AM, Andrew Dunstan  wrote:
  


  
  I don't recall if this has come up before.
  I'm sometimes mildly annoyed when I get on
a new system and find the username missing in my psql prompt. Or
if a customer shows me a screen and I have to ask "which user is
this". If we're dealing with several roles it can get confusing.
My usual .psqlrc has   \set PROMPT1 '%n@%~%R%x%# 'So my suggestion is that we prepend '%n@'
to the default psql PROMPT1 (and maybe PROMPT2).I realize it's not exactly
earth-shattering, but I think it's a bit more user-friendly.(Would be a good beginner project, the
code change would be tiny but there are lots of docs / examples
that we might want to change if we did it.)
  
  cheers
  andrew
  
--
Andrew Dunstan
EDB: https://www.enterprisedb.com

  



Re: session username in default psql prompt?

2023-05-27 Thread Junwang Zhao
I'd like to take this if this is approved ;)

On Sat, May 27, 2023 at 8:52 PM Andrew Dunstan  wrote:
>
> I don't recall if this has come up before.
>
> I'm sometimes mildly annoyed when I get on a new system and find the username 
> missing in my psql prompt. Or if a customer shows me a screen and I have to 
> ask "which user is this". If we're dealing with several roles it can get 
> confusing. My usual .psqlrc has
>
>\set PROMPT1 '%n@%~%R%x%# '
>
> So my suggestion is that we prepend '%n@' to the default psql PROMPT1 (and 
> maybe PROMPT2).
>
> I realize it's not exactly earth-shattering, but I think it's a bit more 
> user-friendly.
>
> (Would be a good beginner project, the code change would be tiny but there 
> are lots of docs / examples that we might want to change if we did it.)
>
>
> cheers
>
>
> andrew
>
> --
> Andrew Dunstan
> EDB: https://www.enterprisedb.com



-- 
Regards
Junwang Zhao