Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fkV5p-0008WV-DR for pgsql-general@arkaria.postgresql.org; Tue, 31 Jul 2018 13:53:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fkV5n-0005WV-S0 for pgsql-general@arkaria.postgresql.org; Tue, 31 Jul 2018 13:53:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fkV5n-0005WN-Jd for pgsql-general@lists.postgresql.org; Tue, 31 Jul 2018 13:53:39 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fkV5l-0006GT-6O for pgsql-general@postgresql.org; Tue, 31 Jul 2018 13:53:39 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id BD0A7713; Tue, 31 Jul 2018 09:53:34 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 31 Jul 2018 09:53:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=TriCsAOKKu8GTKfzb8UMObQktxDTe ZFFj/WCV0towrw=; b=tAdjVnuGYEpBfnIll9zgp3vE8Y2zdC5mlxFh4JQOtc2Ol eguWXY11Qie/P3QXr1xHVxBjtjm1OqxTKinGxCbN9xg8AoCdQUho7stPoD/UUglN WJgSb3muyBY0VJDdB0ebe6hngsKFoXxXCqlp0Oq1FinQXbZHfphWL002E2wxyqOU gZocpyosDeggzwUcfQYYbvI4oBpQNdjsoDyn9mTXDz1TI3F9hsfCeZQd8sdyrhsk XicDGoGeivdhff9Txrt3NPKVLClacocBLWhB95RbzFtxDx5IypMx8GT0C6zPfZoB +gKUHCXh3yaTm1VB28/mciBornTXcwQkYBwtBxBDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=TriCsA OKKu8GTKfzb8UMObQktxDTeZFFj/WCV0towrw=; b=uGthvGqHg368kkN7wwF1D/ 9ICiafUx/t2OAgiKVsVYaH3IozVFFUSnH0d9XMXh4Xmr24dZ5mlrP5rlc0+gUYYm gH+u2Pv4i6oaa01+zSw4F2nWox5JlwrGprKzZrjHJ3+OExOLLjoyZ6Vf3EreaknR ezyTtUBzyVA7iaqWqDYxB+TgvDWDJI8qzudlm652Q8KJOH5kCaZC5lRfgvsHK9TZ CO0VzQ1w4iexaLW6JdfrDRSdzTmlHTkAUM97PYR1LI9CtQ6CPJHy0W8n5JKFX/pB fMJFLQ4aB6rMAELe0yaJ4QO+j/WC6Hq4+fEq6xAXlPAQTikU38PfWzvIWaSGRh8Q == X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.3] (unknown [71.212.134.181]) by mail.messagingengine.com (Postfix) with ESMTPA id A623410284; Tue, 31 Jul 2018 09:53:33 -0400 (EDT) Subject: Re: Design of a database table To: hmidi slim Cc: pgsql-general@postgresql.org References: From: Adrian Klaver Message-ID: <70eaca06-ab66-0c34-1da4-cf9233d03134@aklaver.com> Date: Tue, 31 Jul 2018 06:53:32 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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.klaver@aklaver.com