public inbox for [email protected]
help / color / mirror / Atom feedFrom: Ron Johnson <[email protected]>
To: pgsql-general <[email protected]>
Subject: INTERVAL MINUTE TO SECOND didn't do what I thought it would do
Date: Wed, 8 Jan 2025 14:00:00 -0500
Message-ID: <CANzqJaAxzAO6ye9r3_T2HA_g1myZTEFH+z7uSzBf57Bh2ykWVg@mail.gmail.com> (raw)
PG 14.13
The goal of "(now() - query_start)::INTERVAL MINUTE TO SECOND" column is to
see how many minutes and seconds ago that the query started. (Why?
Because that's useful to me, and the people I show the output to when
queries run for more than a few minutes. We don't need to see hours and
days; just the total MMMMM:SS.mmm.)
I'd hoped that ::INTERVAL MINUTE TO SECOND would do the trick, but MINUTE
TO SECOND seems to be ignored.
Is there cast magic that does what I want?
TAPc=# select pid
,datname as db, usename
,to_char(query_start, 'YYYY-MM-DD HH24:MI:SS.MS') as qry_start
,(now() - query_start)::INTERVAL MINUTE TO SECOND as qry_elapsed
,cast(state as char(11)) as state
from pg_stat_activity
WHERE pid != pg_backend_pid()
and state != 'idle';
pid | db | usename | qry_start | qry_elapsed
| state
---------+------+------------+-------------------------+-------------------------+-------------
657996 | | replicator | 2024-11-11 21:03:00.992 | 57 days
16:38:22.342449 | active
4070070 | TAPc | TAP | 2025-01-08 13:41:23.202 | 00:00:00.132817
| active
4070069 | TAPc | TAP | 2025-01-08 13:41:23.140 | 00:00:00.194222
| active
4070065 | TAPc | TAP | 2025-01-08 13:41:23.238 | 00:00:00.096418
| active
(4 rows)
--
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!
view thread (5+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: INTERVAL MINUTE TO SECOND didn't do what I thought it would do
In-Reply-To: <CANzqJaAxzAO6ye9r3_T2HA_g1myZTEFH+z7uSzBf57Bh2ykWVg@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox