Re: How to find first non-vacation day

From: Philip Hallstrom <postgresql(at)philip(dot)pjkh(dot)com>
To: Andrus Moor <eetasoft(at)online(dot)ee>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to find first non-vacation day
Date: 2006-02-03 22:10:04
Message-ID: 20060203160935.E60131@bravo.pjkh.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> I have a table of vacations
>
> create table vacation (
> id integer primary key,
> dstart date,
> dend date );
>
>
> I need to find first non-vacation day before given date.
>
> This can be done using the following procedural vfp code
>
> function nonvacation( dbefore )
>
> for i=dbefore to date(1960,1,1) step -1
> select vacation
> locate for between( i, dstart, dend )
> if not found()
> return i
> endif
> endfor
> return null
>
> but this is very slow
>
> How to implement this as sql select statement ?

Haven't given a lot of thought to this, but why not?

SELECT *
FROM vacation
WHERE
dstart < '2006-02-03'
ORDER BY dstart DESC
LIMIT 1

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Philip Hallstrom 2006-02-03 22:17:15 Re: How to find first non-vacation day
Previous Message Andrus Moor 2006-02-03 21:35:44 How to find first non-vacation day