Proposal: %T Prompt parameter for psql for current time (like Oracle has)

Started by Kirk Wolakover 3 years ago7 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t47548
psql -h localhost -U postgres

Built from patchset v3 (message #3), July 28, 2026 at 01:02 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t47548_3 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t47548_3 && git checkout t47548_3

Patchset v3 (message #3) is on t47548_3

Jump to latest
#1Kirk Wolak
wolakk@gmail.com

Attachments:

v2-0001-Time-option-added-to-psql-prompt.patchtext/plain; charset=US-ASCII; name=v2-0001-Time-option-added-to-psql-prompt.patchDownload+18-2
#2Jim Jones
jim.jones@uni-muenster.de
In reply to: Kirk Wolak (#1)
Re: Proposal: %T Prompt parameter for psql for current time (like Oracle has)

On 01.03.23 01:59, Kirk Wolak wrote:

I cannot get the last email to show up for the commitfest.
This is version 2 of the original patch. [1]
Thanks Jim!

[1]/messages/by-id/CACLU5mSRwHr_8z=enMj-nXF1tmC7+Jn5heZQNiKuLyxYUtL2fg@mail.gmail.com

Regards Kirk.

The patch didn't pass the SanityCheck:

https://cirrus-ci.com/task/5445242183221248?logs=build#L1337

missing a header perhaps?

#include "time.h"

Best, Jim

#3Kirk Wolak
wolakk@gmail.com
In reply to: Jim Jones (#2)
Re: Proposal: %T Prompt parameter for psql for current time (like Oracle has)

On Wed, Mar 1, 2023 at 4:41 AM Jim Jones <jim.jones@uni-muenster.de> wrote:

On 01.03.23 01:59, Kirk Wolak wrote:

I cannot get the last email to show up for the commitfest.
This is version 2 of the original patch. [1]
Thanks Jim!

[1]

/messages/by-id/CACLU5mSRwHr_8z=enMj-nXF1tmC7+Jn5heZQNiKuLyxYUtL2fg@mail.gmail.com

Regards Kirk.

The patch didn't pass the SanityCheck:

https://cirrus-ci.com/task/5445242183221248?logs=build#L1337

missing a header perhaps?

#include "time.h"

Best, Jim

Thanks, corrected, and confirmed Unix line endings.
FWIW, the simplest way to test it is with this command (I usually get it
wrong on the first guess)

\set PROMPT1 %T ' ' :PROMPT1

Kirk

Attachments:

t47548_3
v3-0001-Time-option-added-to-psql-prompt.patchtext/plain; charset=US-ASCII; name=v3-0001-Time-option-added-to-psql-prompt.patchDownload+19-2
#4Jim Jones
jim.jones@uni-muenster.de
In reply to: Kirk Wolak (#3)
Re: Proposal: %T Prompt parameter for psql for current time (like Oracle has)

On 01.03.23 17:13, Kirk Wolak wrote:

Thanks, corrected, and confirmed Unix line endings.
FWIW, the simplest way to test it is with this command (I usually get
it wrong on the first guess)

\set PROMPT1 %T ' ' :PROMPT1

Kirk

Nice. The patch applies clean and the cfbots seem much happier now - all
passed.

17:23:19 postgres=# SELECT now();
              now
-------------------------------
 2023-03-01 17:23:19.807339+01
(1 row)

The docs render also just fine. I'm now wondering if HH24:MI:SS should
be formatted with, e.g. using <literal>

"The current time on the client in <literal>HH24:MI:SS</literal> format."

But that I'll leave to the docs experts to judge :)

Best, Jim

#5Kirk Wolak
wolakk@gmail.com
In reply to: Jim Jones (#4)
Re: Proposal: %T Prompt parameter for psql for current time (like Oracle has)

On Wed, Mar 1, 2023 at 11:55 AM Jim Jones <jim.jones@uni-muenster.de> wrote:

On 01.03.23 17:13, Kirk Wolak wrote:

Thanks, corrected, and confirmed Unix line endings.
FWIW, the simplest way to test it is with this command (I usually get it
wrong on the first guess)

\set PROMPT1 %T ' ' :PROMPT1

Kirk

Nice. The patch applies clean and the cfbots seem much happier now - all
passed.

17:23:19 postgres=# SELECT now();
now
-------------------------------
2023-03-01 17:23:19.807339+01
(1 row)

The docs render also just fine. I'm now wondering if HH24:MI:SS should be
formatted with, e.g. using <literal>

"The current time on the client in <literal>HH24:MI:SS</literal> format."

But that I'll leave to the docs experts to judge :)

Best, Jim

Thanks Jim.

I hope one of the Docs experts chime in. It's easy enough to fix. Just
not sure if it's required.
What a great learning experience!

#6Laurenz Albe
laurenz.albe@cybertec.at
In reply to: Kirk Wolak (#3)
Re: Proposal: %T Prompt parameter for psql for current time (like Oracle has)

On Wed, 2023-03-01 at 11:13 -0500, Kirk Wolak wrote:

Thanks, corrected, and confirmed Unix line endings.

The patch builds fine and works as intended.

I leave it to the committers to decide whether the patch is worth the
effort or not, given that you can get a similar effect with %`date`.
It adds some value by being simpler and uniform across all platforms.

I'll mark the patch as "ready for committer".

Yours,
Laurenz Albe

#7Kirk Wolak
wolakk@gmail.com
In reply to: Laurenz Albe (#6)
Re: Proposal: %T Prompt parameter for psql for current time (like Oracle has)

On Thu, Mar 2, 2023 at 9:56 AM Laurenz Albe <laurenz.albe@cybertec.at>
wrote:

On Wed, 2023-03-01 at 11:13 -0500, Kirk Wolak wrote:

Thanks, corrected, and confirmed Unix line endings.

The patch builds fine and works as intended.

I leave it to the committers to decide whether the patch is worth the
effort or not, given that you can get a similar effect with %`date`.
It adds some value by being simpler and uniform across all platforms.

I'll mark the patch as "ready for committer".

Yours,
Laurenz Albe

Thanks Laurenz.

To be clear, I use windows AND linux, and I share my file between them.

in linux: `date +%H:%M:%S` is used
in windows: `ECHO %time%`

so, I wrote a ts.cmd and ts.sh so I could share one prompt: `ts`
but now every time I connect a new account to this file, I have to go
find/copy my ts file.
Same when I share it with other developers.

This was the pain that started the quest.
Thanks to everyone for their support!