Re: Interval Question

From: Terry Lee Tucker <terry(at)esc1(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Interval Question
Date: 2005-01-11 16:03:14
Message-ID: 200501111103.14595.terry@esc1.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Apparently, if DateStyle is set to Sql, it always returns the absolute value.
Is this due to some Sql standard or is it a bug?

On Tuesday 11 January 2005 10:19 am, Tom Lane saith:
> Terry Lee Tucker <terry(at)esc1(dot)com> writes:
> > I thought that subtracting the larger interval from
> > the small would return this but it is always the absolute value.
>
> Eh?
>
> regression=# set DateStyle TO ISO;
> SET
> regression=# select '@ 3 days 4 hours 17 mins'::interval -
> regression-# '@ 3 days 6 hours 17 mins'::interval;
> ?column?
> -----------
> -02:00:00
> (1 row)
>
> regression=# set DateStyle TO postgres;
> SET
> regression=# select '@ 3 days 4 hours 17 mins'::interval -
> regression-# '@ 3 days 6 hours 17 mins'::interval;
> ?column?
> ---------------
> @ 2 hours ago
> (1 row)
>
> and as for detecting whether it's negative,
>
> regression=# select ('@ 3 days 4 hours 17 mins'::interval -
> regression(# '@ 3 days 6 hours 17 mins'::interval) < '0'::interval;
> ?column?
> ----------
> t
> (1 row)
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
> joining column's datatypes do not match

--
Quote: 88
"The best view of big government is in the rearview mirror as you're
driving away from it."

--Ronald Reagan

Work: 1-336-372-6812
Cell: 1-336-363-4719
email: terry(at)esc1(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2005-01-11 16:04:43 Re: PL/Perl
Previous Message Terry Lee Tucker 2005-01-11 15:54:25 Re: Interval Question