Re: to_char(interval) --- done?

From: Larry Rosenman <ler(at)lerctr(dot)org>
To: josh(at)agliodbs(dot)com, Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>
Cc: pgsql-hackers(at)postgresql(dot)org, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: to_char(interval) --- done?
Date: 2003-03-26 18:01:30
Message-ID: 150050000.1048701690@lerlaptop.iadfw.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

--On Wednesday, March 26, 2003 09:53:58 -0800 Josh Berkus
<josh(at)agliodbs(dot)com> wrote:

> Larry,
>
>> > What about EXTRACT(months FROM <interval_field>)?
>> >
>> > This annoyingly wraps around if it's more than 12 months, but that was
>> > part of my proposal ...
>> I needed like 5 years (60 months)...
>>
>> So, the wrap around is not good in this case.
>
> Easy:
> CREATE FUNCTION show_months ( interval ) returns text as '
> SELECT CAST( (( extract(years from $1) * 12 ) + extract(months from $1))
> AS text ) || '' months'';
> ' LANGUAGE SQL IMMUTABLE STRICT;
>
> (above not checked for typos)
>
> I'd swear that you posted your question on pgsql-sql and I posted the
> above solution some months ago.
I did post, but this solution did **NOT** get posted. So, I kept my field
as
INT.

BUT, thank you for this.

LER

>
> --
> -Josh Berkus
> Aglio Database Solutions
> San Francisco
>

--
Larry Rosenman http://www.lerctr.org/~ler
Phone: +1 972-414-9812 E-Mail: ler(at)lerctr(dot)org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Stark 2003-03-26 18:51:42 Re: A bad behavior under autocommit off mode
Previous Message Josh Berkus 2003-03-26 17:53:58 Re: to_char(interval) --- done?