Select daterange 列类型的一部分

Select a part from the daterange column type

也许有功能?

SELECT min('[2010-01-01, 2010-02-01)'::daterange); 应该 return: '2010-01-01'

SELECT max('[2010-01-01, 2010-02-01)'::daterange); 应该 return: '2010-01-31'

没有,但是你可以使用upper_incupperlower_inclower函数来编写这样的函数:

WITH dr AS (
  SELECT '[2010-01-01, 2010-02-01)'::daterange r
), t AS (
  SELECT r, lower_inc(r) li, upper_inc(r) ui, lower(r) l, upper(r) u FROM dr
)
SELECT CASE WHEN li THEN l ELSE l + INTERVAL '1 DAY' END AS "range_minimum"
     , CASE WHEN ui THEN u ELSE u - INTERVAL '1 DAY' END AS "range_maximum"
FROM t;

起点:

SELECT lower('[2010-01-01, 2010-02-01)'::daterange);  
01/01/2010

因为包容

对于鞋面:

SELECT CASE WHEN 
      upper_inc('[2010-01-01, 2010-02-01)'::daterange) = 'f' 
   THEN 
       upper('[2010-01-01, 2010-02-01)'::daterange) - interval '1 day' 
   ELSE 
       upper('[2010-01-01, 2010-02-01)'::daterange) END AS dt;  

01/31/2010 00:00:00