Bounding Box Operations

Topological Operations

The topological operations available for the set and span types are given next.

  • Do the values overlap (have values in common)?

    {set,spans} && {set,spans} → boolean

    SELECT intset '{1, 3}' && intset '{2, 3, 4}';
    -- true
    SELECT floatspan '[1, 3)' && floatspan '[3, 4)';
    -- false
    SELECT tstzspan '[2001-01-01, 2001-01-05)' && tstzspan '[2001-01-02, 2001-01-07)';
    -- true
    SELECT floatspanset '{[1, 5),[6, 8)}' && floatspan '[1, 6)';
    -- true
    
  • Does the first value contain the second one?

    {set,spans} @> {base,set,spans} → boolean

    SELECT floatset '{1.5, 2.5}' @> 2.5;
    -- true
    SELECT tstzspan '[2001-01-01, 2001-05-01)' @> timestamptz '2001-02-01';
    -- true
    SELECT floatspanset '{[1, 2),(2, 3)}' @> 2.0;
    -- false
    
  • Is the first value contained by the second one?

    {base,set,spans} <@ {set,spans} → boolean

    SELECT timestamptz '2001-01-10' <@ tstzspan '[2001-01-01, 2001-05-01)';
    -- true
    SELECT floatspan '[2, 5]' <@ floatspan '[1, 5)';
    -- false
    SELECT tstzspan '[2001-02-01, 2001-03-01)' <@ tstzspan '[2001-01-01, 2001-05-01)';
    -- true
    SELECT floatspanset '{[1,2],[3,4]}' <@ floatspan '[1, 6]';
    -- true
    
  • Is the first value adjacent to the second one?

    spans -|- spans → boolean

    SELECT intspan '[2, 6)' -|- intspan '[6, 7)';
    -- true
    SELECT floatspan '[2, 5)' -|- floatspan '(5, 6)';
    -- false
    SELECT floatspanset '{[2, 3],[4, 5)}' -|- floatspan '(5, 6)';
    -- true
    SELECT tstzspanset '{[2001-01-01, 2001-01-02]}' -|- tstzspan '[2001-01-02, 2001-01-03)';
    -- false
    

Position Operations

The position operations available for set and span types are given next. Notice that the operators for time types have an additional # to distinguish them from the operators for number types.

  • Is the first value strictly left of the second one?

    numbers << numbers → boolean

    times <<# times → boolean

    SELECT intspan '[15, 20)' << 20;
    -- true
    SELECT intspanset '{[15, 17],[18, 20)}' << 20;
    -- true
    SELECT floatspan '[15, 20)' << floatspan '(15, 20)';
    -- false
    SELECT dateset '{2001-01-01, 2001-01-02}' <<# dateset '{2001-01-03, 2001-01-05}';
    -- true
    
  • Is the first value strictly to the right of the second one?

    numbers >> numbers → boolean

    times #>> times → boolean

    SELECT intspan '[15, 20)' >> 10;
    -- true
    SELECT floatspan '[15, 20)' >> floatspan '[5, 10]';
    -- true
    SELECT floatspanset '{[15, 17], [18, 20)}' >> floatspan '[5, 10]';
    -- true
    SELECT tstzspan '[2001-01-04, 2001-01-05)' #>>
      tstzspanset '{[2001-01-01, 2001-01-04), [2001-01-05, 2001-01-06)}';
    -- true
    
  • Is the first value not to the right of the second one?

    numbers &< numbers → boolean

    times &<# times → boolean

    SELECT intspan '[15, 20)' &< 18;
    -- false
    SELECT intspanset '{[15, 16],[17, 18)}' &< 18;
    -- true
    SELECT floatspan '[15, 20)' &< floatspan '[10, 20]';
    -- true
    SELECT dateset '{2001-01-02, 2001-01-05}' &<# dateset '{2001-01-01, 2001-01-04}';
    -- false
    
  • Is the first value not to the left of the second one?

    numbers &> numbers → boolean

    times #&> times → boolean

    SELECT intspan '[15, 20)' &> 30;
    -- true
    SELECT floatspan '[1, 6]' &> floatspan '(1, 3)';
    -- false
    SELECT floatspanset '{[1, 2],[3, 4]}' &> floatspan '(1, 3)';
    -- false
    SELECT timestamp '2001-01-01' #&> tstzspan '[2001-01-01, 2001-01-05)';
    -- true