Re: Design of a database table

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: hmidi slim <hmidi(dot)slim2(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Design of a database table
Date: 2018-07-31 13:53:32
Message-ID: 70eaca06-ab66-0c34-1da4-cf9233d03134@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 07/30/2018 11:40 PM, hmidi slim wrote:
> Actually, the data_periods contains a complete range such as
> [2018-09-01,2018-09-30] and data_sub_periods contains sub periods
> contained in this period like:
> [2018-09-05, 2018-09-07]
> [2018-09-09, 2018-09-11]
> [2018-09-12, 2018-09-19]
>
> I make two conditions in order to fetch first if the period
> [2018-09-01,2018-09-30] contained in the first table.If it exists I will
> return the sub periods that overlaps the given period
> where data_periods.period && '[2018-09-01,2018-09-30]'::daterange
> and data_sub_periods  && '[2018-09-01,2018-09-30] '::daterange
>

If data_sub_periods are actually sub periods of period then you should
need only search for the period [2018-09-01,2018-09-30] and join
data_periods_info to period on period.id =
data_periods_info.data_periods_id.

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Lu, Dan 2018-07-31 13:59:43 RE: Question on postgresql.conf
Previous Message Tom Lane 2018-07-31 13:51:55 Re: Question on postgresql.conf