From: Tom Lane <tgl@sss.pgh.pa.us>
To: hmidi slim <hmidi.slim2@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: How to get an inclusive interval when using daterange
Date: Mon, 02 Apr 2018 15:13:56 -0400
Message-ID: <23053.1522696436@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMsqVxtEkr-KwmvoM==+8vruv0hMc9bLd8E+csrRzAxfkx36wg@mail.gmail.com>
References: <CAMsqVxtEkr-KwmvoM==+8vruv0hMc9bLd8E+csrRzAxfkx36wg@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, hmidi.slim2@gmail.com
Subject: Re: How to get an inclusive interval when using daterange
In-Reply-To: <23053.1522696436@sss.pgh.pa.us>
References: <CAMsqVxtEkr-KwmvoM==+8vruv0hMc9bLd8E+csrRzAxfkx36wg@mail.gmail.com> <23053.1522696436@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox