Re: doverlaps() returns null

From: "Andrus" <kobruleht2(at)hot(dot)ee>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: doverlaps() returns null
Date: 2007-05-21 09:49:40
Message-ID: f2rq53$26g9$2@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> You cannot cast +/- infinity timestamp to date

Thank you.

All my dates are in nearest centuries. So I fixed this by creating function

CREATE OR REPLACE FUNCTION public.doverlaps(date,date, date, date, out bool)
immutable AS
$_$
SELECT coalesce($1, date '0001-01-01') <=coalesce($4, date '9999-12-31')
AND
coalesce($2, date '9999-12-31')>=coalesce($3, date '0001-01-01' );
$_$ language sql;

is this best solution ?

> , but you can cast date to timestamp.
> And what's wrong with OVERLAPS? e.g. :
>
> CREATE OR REPLACE FUNCTION
> PUBLIC.DOVERLAPS
> (DATE, DATE, DATE, DATE, OUT BOOL)
> IMMUTABLE AS
> $_$
> SELECT
> (COALESCE($1::TIMESTAMP, TIMESTAMP '-INFINITY')
> , COALESCE($2::TIMESTAMP, TIMESTAMP 'INFINITY')
> )
> OVERLAPS(
> COALESCE($3::TIMESTAMP, TIMESTAMP '-INFINITY')
> , COALESCE($4::TIMESTAMP, TIMESTAMP 'INFINITY'));
> $_$ LANGUAGE SQL;
>
> t=# SELECT doverlaps( NULL, NULL, NULL, NULL);
> doverlaps
> -----------
> t

I'm using this for emplyment, vacation, illness etc. period calculation.
OVERLAPS produces invalid result in this case for DATE as discussed in other
thread.

select doverlaps(date '2007-01-01',date '2007-01-02',date '2007-01-02',date
'2007-01-04');

returns FALSE

When first period end and second period start dates are the the same,
doverlaps() must return TRUE.

Andrus.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Akmal Akmalhojaev 2007-05-21 10:21:52 Role members
Previous Message Oleg Bartunov 2007-05-21 09:42:12 Re: TSearch2 memory usage