Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f34u4-0004Hk-3q for pgsql-general@arkaria.postgresql.org; Mon, 02 Apr 2018 19:14:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f34u3-0003kl-3O for pgsql-general@arkaria.postgresql.org; Mon, 02 Apr 2018 19:14:03 +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 1f34u2-0003kb-Ra for pgsql-general@lists.postgresql.org; Mon, 02 Apr 2018 19:14:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f34tz-0007zF-4W for pgsql-general@postgresql.org; Mon, 02 Apr 2018 19:14:02 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w32JDuq9023054; Mon, 2 Apr 2018 15:13:56 -0400 From: Tom Lane To: hmidi slim cc: pgsql-general@postgresql.org Subject: Re: How to get an inclusive interval when using daterange In-reply-to: References: Comments: In-reply-to hmidi slim message dated "Mon, 02 Apr 2018 19:09:56 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <23052.1522696436.1@sss.pgh.pa.us> Date: Mon, 02 Apr 2018 15:13:56 -0400 Message-ID: <23053.1522696436@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk hmidi slim writes: > When I insert a data into this table I use this query: > insert into availability values ('product x', daterange('2018-02-02', > '2018-03-01', '[]') > So I get a period like this: [2018-02-02, 2018-03-02) Yup. > In my app I tried to subtract a day from the period when I got it from > database.I'm using daterange and not tsrange because the daterange gives me > less execution time when I make tests with a huge number of data.So is > there any way to get an inclusive interval with daterange or I have to use > tsrange to get inclusive intervals? No, daterange will always canonicalize a range into '[)' format. This is explained (perhaps not with adequate clarity) in https://www.postgresql.org/docs/10/static/rangetypes.html#RANGETYPES-DISCRETE The key reason why is to make it clearer which range specifications are equal. For instance, it's not really clear whether ['2018-02-02','2018-03-01'] and ['2018-02-02','2018-03-02') represent the same set of values --- they do if it's a daterange, but not if it's a tsrange. Canonicalizing makes equal ranges look equal. regards, tom lane