Обсуждение: daterange constructor vs cast

Поиск
Список
Период
Сортировка

daterange constructor vs cast

От
Shvidky Andrey
Дата:

Hello!

 

Aren’t these 6 results must be the same?

 

select

       daterange('[20231211', '20231211]')

       ,daterange('[20231211', '20231212)')

       ,daterange('20231211', '20231211', '[]')

       ,daterange('20231211', '20231212', '[)')

       ,'[20231211,20231211]'::daterange

       ,'[20231211,20231212)'::daterange

 

 

daterange|daterange              |daterange              |daterange              |daterange              |daterange              |

---------+-----------------------+-----------------------+-----------------------+-----------------------+-----------------------+

empty    |[2023-12-11,2023-12-12)|[2023-12-11,2023-12-12)|[2023-12-11,2023-12-12)|[2023-12-11,2023-12-12)|[2023-12-11,2023-12-12)|

 

Thanks in advance!

Andrey N. Shvidky.

Re: daterange constructor vs cast

От
Tom Lane
Дата:
Shvidky Andrey <andrey_shvidky@hotmail.com> writes:
> Aren't these 6 results must be the same?

I think you have the wrong idea of how range constructors work.
This:

>        daterange('[20231211', '20231211]')
>        ,daterange('[20231211', '20231212)')

is not valid input really.  It happens to not fail because date_in
ignores garbage punctuation; but nothing is considering those
brackets or parens as indicating range end types.

These are the approved way to do it:

>        ,daterange('20231211', '20231211', '[]')
>        ,daterange('20231211', '20231212', '[)')

            regards, tom lane