Re: FWD: tinterval vs interval on pgsql-novice

From: Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-novice(at)postgresql(dot)org, Hackers List <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: FWD: tinterval vs interval on pgsql-novice
Date: 2000-11-27 18:41:54
Message-ID: 3A22AAF2.996F55E1@alumni.caltech.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-novice

> > Thomas Lockhart would be the authority on this, but my impression is
> > that tinterval is deprecated and will eventually go away in favor of
> > the SQL-standard interval type. If you've found functions that exist
> > for tinterval and not for interval, then that's an item for the TODO
> > list --- please submit details.
> Perhaps I'm not picking up things from the documentation, but it appears to
> me that "interval" is only a time length, while "tinterval" is actually for
> specific times. To use a geometric analogy: interval is a length, while
> tinterval is a specific line segment.
> So it seems to me that interval is just way to generic (or rather,
> tinterval already supports things that I want to do, such as testing for
> overlaps).

TINTERVAL is a poorly supported, old and creaky data type. It is based
on ABSTIME, which is not as capable as TIMESTAMP.

> Am I missing something in the documentation that would explain to me how I
> could use a starttime/length combination (something like abstime/interval,
> or timestamp/interval) to check for overlaps like can be done with tinterval?

Maybe. The SQL9x function/operator OVERLAPS is recognized by PostgreSQL
7.x, and probably does what you want.

Of course, now that I'm testing it, something has broken with OVERLAPS
(in 7.0.3 and current sources). I've defined a function overlaps() which
takes four arguments of timestamp type. The parser recognizes the
OVERLAPS syntax, and converts that to a function call syntax. I've also
defined a few more functions in pg_proc.h in the "SQL language" to map
variations of arguments, say (timestamp,interval,timestamp,interval), to
the underlying single implementation. Pretty sure that I tested this
exhaustively (?). That mapping now fails (hmm, remind me to add this to
the regression tests) with a parser error.

Test cases would be:

select ('today', 'tomorrow') OVERLAPS ('yesterday', 'now');

and

select ('today', interval '1 day') OVERLAPS ('yesterday', interval '18
hours');

(the second one fails). Now that I look, this breakage was introduced in
March when "we" expunged operators allowed as identifiers (Tom Lane and
I have blood on our hands on this one ;) See gram.y around line 5409.
Suggestions?

- Thomas

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Don Baccus 2000-11-27 18:42:01 Re: Question about Oracle compatibility
Previous Message Don Baccus 2000-11-27 18:38:24 Re: Question about Oracle compatibility

Browse pgsql-novice by date

  From Date Subject
Next Message Eduardo Kotujansky 2000-11-27 19:41:20 Can not find -lpq
Previous Message Don Baccus 2000-11-27 18:30:27 Re: Re: [NOVICE] Re: re : PHP and persistent connections