Update lower/upper bound of range type

前端 未结 3 1401
走了就别回头了
走了就别回头了 2021-02-08 19:13

I have column of tstzrange type (timestamp with time zone range) and I need to update only upper or lower bound of this value (and keep inclusive/exclusive boundari

3条回答
  •  暖寄归人
    2021-02-08 19:51

    Improvement to Mikes great answer.

    When we use the pseudo-type anyrange, we only need a single function:

    CREATE OR REPLACE FUNCTION range_bounds(IN range anyrange)
        RETURNS CHAR(2) AS
    $$
    SELECT CASE WHEN lower_inc(range) THEN '[' ELSE '(' END ||
           CASE WHEN upper_inc(range) THEN ']' ELSE ')' END;
    $$
    LANGUAGE SQL
    RETURNS NULL ON NULL INPUT;
    

提交回复
热议问题