Re: question about postgresql time intervals

From: Michael Glaesemann <grzm(at)myrealbox(dot)com>
To: lgray(at)unitrends(dot)com
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: question about postgresql time intervals
Date: 2006-03-14 23:58:03
Message-ID: 8B817E7D-C396-4CF3-B82A-BFE8855BC3F5@myrealbox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You will get better, faster answers by sending questions to a
PostgreSQL mailing list. By emailing me directly you may not get a
timely response if I don't have time to answer. Others can then
answer and learn from the subsequent discussion. I'm ccing this to
pgsql-general.

On Mar 15, 2006, at 6:45 , Linda wrote:

> Hi, Michael
>
> I have a question about the output format of the INTERVAL type in
> version
> 8.1.1. In previous versions, I could do the following:
>
> select (uptime::varchar)::interval from machine_info;
>
> where uptime is an INTEGER type, the number of seconds the machine
> has been
> up since last reboot. This used to produce output in this format:
> 21 days 02:47:04
>
> Now in v8.1.1, the output format is
> 506:47:04
>
> How can I get the "justified" output as before? Is there some
> setting of
> datestyle that affects the output? I have tried specifying
> "interval day
> to second" but that doesn't work. Using the new justify_hours
> function
> works, but is it possible to do something that will run on older
> versions
> of postgresql?
>
> Thanks,
> Linda
>
> --
> Linda Gray
> Unitrends Corporation
> 803.454.0300 ext. 241
>

justify_hours is also in 8.1 and should do what you want.

test=# select '506:47:04'::interval;
interval
-----------
506:47:04
(1 row)

test=# select justify_hours('506:47:04'::interval);
justify_hours
------------------
21 days 02:47:04
(1 row)

test=# select version();

version
------------------------------------------------------------------------
----------------------------------------------------------------------
PostgreSQL 8.1.3 on powerpc-apple-darwin8.4.0, compiled by GCC
powerpc-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc.
build 5247)
(1 row)

Michael Glaesemann
grzm myrealbox com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kevin Grittner 2006-03-15 00:00:03 Re: [pgsql-advocacy] Wisconsin Circuit Court Access (WCCA) on
Previous Message Devrim GUNDUZ 2006-03-14 22:00:33 Re: Clustered PostgreSQL