From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
---|---|
To: | Ron Johnson <ronljohnsonjr(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: INTERVAL MINUTE TO SECOND didn't do what I thought it would do |
Date: | 2025-01-08 20:07:09 |
Message-ID: | 071854d0-c524-436c-84d1-309aa096904d@aklaver.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 1/8/25 11:58 AM, Ron Johnson wrote:
> On Wed, Jan 8, 2025 at 2:43 PM Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com
> <mailto:adrian(dot)klaver(at)aklaver(dot)com>> 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.
>
> >
> > 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
--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Ron Johnson | 2025-01-08 20:19:31 | Re: INTERVAL MINUTE TO SECOND didn't do what I thought it would do |
Previous Message | Ron Johnson | 2025-01-08 19:58:28 | Re: INTERVAL MINUTE TO SECOND didn't do what I thought it would do |