Re: [SQL] Bug with Daylight Savings Time & Interval

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Thomas Lockhart <lockhart(at)fourpalms(dot)org>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [SQL] Bug with Daylight Savings Time & Interval
Date: 2002-05-22 14:45:39
Message-ID: 1022078739.24264.1096.camel@linda
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers pgsql-sql

Switched to -hackers from -sql and -bugs.

On Tue, 2002-05-21 at 16:24, Thomas Lockhart wrote:
>
> You can continue to explore the current behavior and to form an opinion
> on what correct behavior should be. I've resisted adding fields to the
> internal interval type for performance and design reasons. As previously
> mentioned, blind verbatim compliance with SQL9x may suggest breaking our
> INTERVAL type into a bunch of pieces corresponding to the different
> interval ranges specified in the standard. However, the SQL standard is
> choosing to cover a small subset of common usage to avoid dealing with
> the implementation complexities and usage patterns which are uncovered
> when trying to do more.

It's worth pointing out that the same syntax is in SQL92, so I conclude
that no one could think how to improve it through a seven year period.

I don't want to dispose of the existing INTERVAL type, but I would like
the functionality offered by the SQL99 types. For example, I want to be
able to use INTERVAL HOUR(3) TO MINUTE to record the time taken by some
industrial process and I don't want '125 hours 15 minutes' converted
into '5 days 05:15'.

You talk of breaking interval into a number of pieces, but I don't see
the need. You have already implemented half of what is needed. The
other part needed is to record the leading field precision, which we can
surely do in typmod, where you already store the fractional precision.
At present you have in AdjustIntervalForTypmod():

int range = ((typmod >> 16) & 0x7FFF);
int precision = (typmod & 0xFFFF);

and since precision is limited to the range 0-6, we should certainly be
able to fit the leading field precision into the same space:

int frac_precision = (typmod & 0xFF); /* default is 6 */
int lead_precision = ((typmod >> 8) & 0xFF); /* default is 2 */

all that is left is a set of rules to validate input and to format
output according to the given precision, and to change the parser
slightly to get the SQL99 syntax right..

Now I'm sure I'm oversimplifying, but where?

As to other common usage, I can see benefits in extending the subtypes
to include WEEK, and this is conceptually merely an extension of the
existing SQL99 DAY TO SECOND type. What other usage do you see that can
reasonably be translated from fuzzy human talk into solid data? Years
and months are already handled and can be used meaningfully. What you
can't do in SQL99 is translate from exact INTERVAL DAY TO SECOND to
fuzzy INTERVAL YEAR TO MONTH. I can't see why one should want to, but
if you do, our existing type system would let us cast INTERVAL DAY TO
SECOND to INTERVAL, which already does this in a satisfactorily fuzzy
way. I can even conceive of doing the conversion using a configured
choice out of a set of fuzzy conversion options. For example: configure
year to be 360, 365 or 365.2425 days; configure month to be year/12 or
30 days or 4 weeks; and so on.

--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C

"We are troubled on every side, yet not distressed; we
are perplexed, but not in despair; persecuted, but not
forsaken; cast down, but not destroyed; Always bearing
about in the body the dying of the Lord Jesus, that
the life also of Jesus might be made manifest in our
body." II Corinthians 4:8-10

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message pgsql-bugs 2002-05-22 15:54:35 Bug #672: timestamp() converts timezone in wrong direction
Previous Message Tom Lane 2002-05-22 14:12:30 Re: Bug #671: server corrupt

Browse pgsql-hackers by date

  From Date Subject
Next Message Hannu Krosing 2002-05-22 14:48:54 Re: Redhat 7.3 time manipulation bug
Previous Message Tom Lane 2002-05-22 14:28:51 Re: Edge case problem with pg_dump

Browse pgsql-sql by date

  From Date Subject
Next Message Christoph Haller 2002-05-22 15:17:01 Bug with ORDER BY expression [ ASC | DESC ] ?
Previous Message Tille, Andreas 2002-05-22 14:36:22 Re: Turning column into row