public inbox for [email protected]  
help / color / mirror / Atom feed
From: Ron Johnson <[email protected]>
To: pgsql-general <[email protected]>
Subject: Re: INTERVAL MINUTE TO SECOND didn't do what I thought it would do
Date: Wed, 8 Jan 2025 15:19:31 -0500
Message-ID: <CANzqJaCust-DPYga05FAOmJ+Wsy1KuidtNVP1uvMft7kri4vqQ@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CANzqJaAxzAO6ye9r3_T2HA_g1myZTEFH+z7uSzBf57Bh2ykWVg@mail.gmail.com>
	<[email protected]>
	<CANzqJaDvKxd=EU2ofTBm9xyWFPGqCfo8MEnLoOZUZgiS=AK=3w@mail.gmail.com>
	<[email protected]>

On Wed, Jan 8, 2025 at 3:07 PM Adrian Klaver <[email protected]>
wrote:

>
>
> On 1/8/25 11:58 AM, Ron Johnson wrote:
> > On Wed, Jan 8, 2025 at 2:43 PM Adrian Klaver <[email protected]
> > <mailto:[email protected]>> wrote:
> >
>
> >      > I'd hoped that ::INTERVAL MINUTE TO SECOND would do the trick, but
> >      > MINUTE TO SECOND seems to be ignored.
> >
> >       From here:
> >
> >
> https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-INTERVAL-INPUT
> <
> https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-INTERVAL-INPUT
> >
> >
> >     "Also, field values “to the right” of the least significant field
> >     allowed by the fields specification are silently discarded. For
> >     example,
> >     writing INTERVAL '1 day 2:03:04' HOUR TO MINUTE results in dropping
> the
> >     seconds field, but not the day field."
> >
> >
> > I read that, but it did not mention that the day values are retained.
>
> I suggest reading the entire section(8.5.4. Interval Input) as well as
> 8.5.5. Interval Output.
>

I did, but either missed something or did not interpret it correctly.


> >
> >      >
> >      > Is there cast magic that does what I want?
> >
> >     The only way I can think of extract the epoch from the interval and
> >     pass
> >     to a function that builds what you want.
> >
> >
> > I was afraid of that.  Must decide if it's worth the time.
> >
> If you don't mind decimal minutes, a quick and dirty solution is:
>
> select extract(epoch from (now() - '2025-01-07 14:15:32'::timestamptz))
> / 60;
>
> 1301.5244606333333333
>

That's what I currently do, using to_char() to add commas and display 3
decimal places.

-- 
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!


view thread (5+ messages)

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: <CANzqJaCust-DPYga05FAOmJ+Wsy1KuidtNVP1uvMft7kri4vqQ@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