On Fri, Feb 24, 2023 at 7:09 AM Jim Jones <jim.jo...@uni-muenster.de> wrote:
> On 23.02.23 20:55, Kirk Wolak wrote: > > Everyone, > ... SQL_EXEC_TIME > > I think like ROW_COUNT, it should not change because of internal > > commands. > > So, you guys +1 this thing, give additional comments. When the > > feedback settles, I commit to making it happen. > > > > Thanks, Kirk > > > I can see it being pretty handy to check if a certain task involving two > different terminal windows was done in the right order. Basically to see > what went wrong, e.g. "did I really stop the master database before > promoting the replica?" > > +1 ! > > Best, Jim > Jim, thanks, here is that patch for the %T option, but I think you did a +1 for the new psql variable :SQL_EXEC_TIME. I realized my communication style needs to be cleaner, I caused that with the lead in. I created this proposal because I felt it was an excellent suggestion, and I think it will be trivial to implement, although it will involve a lot more testing... MANY times, I have run a query that took a touch too long, and I was wondering how long EXACTLY did that take. This makes it easy \echo :SQL_EXEC_TIME (Well, I think it will be SQL_EXEC_ELAPSED) regards, kirk
From eaf6d05028052a3ccaa8d980953ac4fd75255250 Mon Sep 17 00:00:00 2001 From: Kirk Wolak <wol...@gmail.com> Date: Thu, 23 Feb 2023 17:52:09 +0000 Subject: [PATCH] Time option added to psql prompt This adds a useful time option to the prompt: %T. Which does not require a wasteful backquoted shell command which is also not compatible between operating systems. The format is simply HH24:MI:SS no other options available by design! Author: Kirk Wolak <wol...@gmail.com> Reviewed-By: Andrey Borodin <amboro...@acm.org> Reviewed-By: Nikolay Samokhvalov <samokhva...@gmail.com> Thread: https://postgr.es/m/CACLU5mSRwHr_8z%3DenMj-nXF1tmC7%2BJn5heZQNiKuLyxYUtL2fg%40mail.gmail.com --- doc/src/sgml/ref/psql-ref.sgml | 9 +++++++++ src/bin/psql/prompt.c | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index dc6528dc11d..04ab9eeb8c0 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -4575,6 +4575,15 @@ testdb=> <userinput>INSERT INTO my_table VALUES (:'content');</userinput> </listitem> </varlistentry> + <varlistentry id="app-psql-prompting-t-uc"> + <term><literal>%T</literal></term> + <listitem> + <para> + The current time on the client in HH24:MI:SS format. + </para> + </listitem> + </varlistentry> + <varlistentry id="app-psql-prompting-x"> <term><literal>%x</literal></term> <listitem> diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.c index 969cd9908e5..a590c27389b 100644 --- a/src/bin/psql/prompt.c +++ b/src/bin/psql/prompt.c @@ -41,6 +41,7 @@ * or a ! if session is not connected to a database; * in prompt2 -, *, ', or "; * in prompt3 nothing + * %T - time in HH24:MI:SS format * %x - transaction status: empty, *, !, ? (unknown or no connection) * %l - The line number inside the current statement, starting from 1. * %? - the error code of the last query (not yet implemented) @@ -223,7 +224,14 @@ get_prompt(promptStatus_t status, ConditionalStack cstack) break; } break; - + /* output HH24:MI:SS */ + case 'T': + { + time_t current_time = time(NULL); + struct tm *tm_info = localtime(¤t_time); + sprintf(buf, "%02d:%02d:%02d", tm_info->tm_hour, tm_info->tm_min, tm_info->tm_sec); + } + break; case 'x': if (!pset.db) buf[0] = '?'; -- GitLab