Re: How to get an inclusive interval when using daterange - Mailing list pgsql-general

From Tom Lane
Subject Re: How to get an inclusive interval when using daterange
Date
Msg-id 23053.1522696436@sss.pgh.pa.us
Whole thread Raw
In response to How to get an inclusive interval when using daterange  (hmidi slim <hmidi.slim2@gmail.com>)
List pgsql-general
hmidi slim <hmidi.slim2@gmail.com> 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


pgsql-general by date:

Previous
From: hmidi slim
Date:
Subject: How to get an inclusive interval when using daterange
Next
From: Michael Paquier
Date:
Subject: Re: PostgreSQL Cascade streaming replication problem