Re: How to get an inclusive interval when using daterange

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: How to get an inclusive interval when using daterange
Дата
Msg-id 23053.1522696436@sss.pgh.pa.us
обсуждение исходный текст
Ответ на How to get an inclusive interval when using daterange  (hmidi slim <hmidi.slim2@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: hmidi slim
Дата:
Сообщение: How to get an inclusive interval when using daterange
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: PostgreSQL Cascade streaming replication problem