Re: Having trouble with Interval computation

From: Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu>
To: Jim Ballard <jballard(at)netezza(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Having trouble with Interval computation
Date: 2001-07-16 21:53:28
Message-ID: 3B536258.4832845B@fourpalms.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> I'd like to get the difference between two timestamp columns expressed
> as an interval with units "year to month."
...
> What is the proper way to express this in Postgres? Will the standard
> form be supported at some point?

lockhart=# select age('today', '1957-06-13');
age
-----------------------
44 years 1 mon 3 days
(1 row)

lockhart=# select date_trunc('month', age('today', '1957-06-13'));
date_trunc
----------------
44 years 1 mon
(1 row)

Note that if the age() function is not used, and instead you use the
subtraction operator, then the result is zero, since the operator gives
a days/hours/min/sec result and does not preserve *any* year or month
information.

"Standard form", that is SQL9x rather than Ingres, will likely be
supported at some point, maybe sooner rather than later if the syntax
can fit into our parser.

hth

- Thomas

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2001-07-16 21:57:10 Re: Postmaster
Previous Message Jeff 2001-07-16 21:25:08 vb 6 and pgsql