Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  cube.out   Sprache: unbekannt

 
Spracherkennung für: .out vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

--
--  Test cube datatype
--
CREATE EXTENSION cube;
-- Check whether any of our opclasses fail amvalidate
SELECT amname, opcname
FROM pg_opclass opc LEFT JOIN pg_am am ON am.oid = opcmethod
WHERE opc.oid >= 16384 AND NOT amvalidate(opc.oid);
 amname | opcname 
--------+---------
(0 rows)

--
-- testing the input and output functions
--
-- Any number (a one-dimensional point)
SELECT '1'::cube AS cube;
 cube 
------
 (1)
(1 row)

SELECT '-1'::cube AS cube;
 cube 
------
 (-1)
(1 row)

SELECT '1.'::cube AS cube;
 cube 
------
 (1)
(1 row)

SELECT '-1.'::cube AS cube;
 cube 
------
 (-1)
(1 row)

SELECT '.1'::cube AS cube;
 cube  
-------
 (0.1)
(1 row)

SELECT '-.1'::cube AS cube;
  cube  
--------
 (-0.1)
(1 row)

SELECT '1.0'::cube AS cube;
 cube 
------
 (1)
(1 row)

SELECT '-1.0'::cube AS cube;
 cube 
------
 (-1)
(1 row)

SELECT 'infinity'::cube AS cube;
    cube    
------------
 (Infinity)
(1 row)

SELECT '-infinity'::cube AS cube;
    cube     
-------------
 (-Infinity)
(1 row)

SELECT 'NaN'::cube AS cube;
 cube  
-------
 (NaN)
(1 row)

SELECT '.1234567890123456'::cube AS cube;
         cube         
----------------------
 (0.1234567890123456)
(1 row)

SELECT '+.1234567890123456'::cube AS cube;
         cube         
----------------------
 (0.1234567890123456)
(1 row)

SELECT '-.1234567890123456'::cube AS cube;
         cube          
-----------------------
 (-0.1234567890123456)
(1 row)

-- simple lists (points)
SELECT '()'::cube AS cube;
 cube 
------
 ()
(1 row)

SELECT '1,2'::cube AS cube;
  cube  
--------
 (12)
(1 row)

SELECT '(1,2)'::cube AS cube;
  cube  
--------
 (12)
(1 row)

SELECT '1,2,3,4,5'::cube AS cube;
      cube       
-----------------
 (12345)
(1 row)

SELECT '(1,2,3,4,5)'::cube AS cube;
      cube       
-----------------
 (12345)
(1 row)

-- double lists (cubes)
SELECT '(),()'::cube AS cube;
 cube 
------
 ()
(1 row)

SELECT '(0),(0)'::cube AS cube;
 cube 
------
 (0)
(1 row)

SELECT '(0),(1)'::cube AS cube;
  cube   
---------
 (0),(1)
(1 row)

SELECT '[(0),(0)]'::cube AS cube;
 cube 
------
 (0)
(1 row)

SELECT '[(0),(1)]'::cube AS cube;
  cube   
---------
 (0),(1)
(1 row)

SELECT '(0,0,0,0),(0,0,0,0)'::cube AS cube;
     cube     
--------------
 (0000)
(1 row)

SELECT '(0,0,0,0),(1,0,0,0)'::cube AS cube;
           cube            
---------------------------
 (0000),(1000)
(1 row)

SELECT '[(0,0,0,0),(0,0,0,0)]'::cube AS cube;
     cube     
--------------
 (0000)
(1 row)

SELECT '[(0,0,0,0),(1,0,0,0)]'::cube AS cube;
           cube            
---------------------------
 (0000),(1000)
(1 row)

-- invalid input: parse errors
SELECT ''::cube AS cube;
ERROR:  invalid input syntax for cube
LINE 1: SELECT ''::cube AS cube;
               ^
DETAIL:  syntax error at end of input
SELECT 'ABC'::cube AS cube;
ERROR:  invalid input syntax for cube
LINE 1: SELECT 'ABC'::cube AS cube;
               ^
DETAIL:  syntax error at or near "A"
SELECT '[]'::cube AS cube;
ERROR:  invalid input syntax for cube
LINE 1: SELECT '[]'::cube AS cube;
               ^
DETAIL:  syntax error at or near "]"
SELECT '[()]'::cube AS cube;
ERROR:  invalid input syntax for cube
LINE 1: SELECT '[()]'::cube AS cube;
               ^
DETAIL:  syntax error at or near "]"
SELECT '[(1)]'::cube AS cube;
ERROR:  invalid input syntax for cube
LINE 1: SELECT '[(1)]'::cube AS cube;
               ^
DETAIL:  syntax error at or near "]"
SELECT '[(1),]'::cube AS cube;
ERROR:  invalid input syntax for cube
LINE 1: SELECT '[(1),]'::cube AS cube;
               ^
DETAIL:  syntax error at or near "]"
SELECT '[(1),2]'::cube AS cube;
ERROR:  invalid input syntax for cube
LINE 1: SELECT '[(1),2]'::cube AS cube;
               ^
DETAIL:  syntax error at or near "2"
SELECT '[(1),(2),(3)]'::cube AS cube;
ERROR:  invalid input syntax for cube
LINE 1: SELECT '[(1),(2),(3)]'::cube AS cube;
               ^
DETAIL:  syntax error at or near ","
SELECT '1,'::cube AS cube;
ERROR:  invalid input syntax for cube
LINE 1: SELECT '1,'::cube AS cube;
               ^
DETAIL:  syntax error at end of input
SELECT '1,2,'::cube AS cube;
ERROR:  invalid input syntax for cube
LINE 1: SELECT '1,2,'::cube AS cube;
               ^
DETAIL:  syntax error at end of input
SELECT '1,,2'::cube AS cube;
ERROR:  invalid input syntax for cube
LINE 1: SELECT '1,,2'::cube AS cube;
               ^
DETAIL:  syntax error at or near ","
SELECT '(1,)'::cube AS cube;
ERROR:  invalid input syntax for cube
LINE 1: SELECT '(1,)'::cube AS cube;
               ^
DETAIL:  syntax error at or near ")"
SELECT '(1,2,)'::cube AS cube;
ERROR:  invalid input syntax for cube
LINE 1: SELECT '(1,2,)'::cube AS cube;
               ^
DETAIL:  syntax error at or near ")"
SELECT '(1,,2)'::cube AS cube;
ERROR:  invalid input syntax for cube
LINE 1: SELECT '(1,,2)'::cube AS cube;
               ^
DETAIL:  syntax error at or near ","
-- invalid input: semantic errors and trailing garbage
SELECT '[(1),(2)],'::cube AS cube; -- 0
ERROR:  invalid input syntax for cube
LINE 1: SELECT '[(1),(2)],'::cube AS cube;
               ^
DETAIL:  syntax error at or near ","
SELECT '[(1,2,3),(2,3)]'::cube AS cube; -- 1
ERROR:  invalid input syntax for cube
LINE 1: SELECT '[(1,2,3),(2,3)]'::cube AS cube;
               ^
DETAIL:  Different point dimensions in (1,2,3) and (2,3).
SELECT '[(1,2),(1,2,3)]'::cube AS cube; -- 1
ERROR:  invalid input syntax for cube
LINE 1: SELECT '[(1,2),(1,2,3)]'::cube AS cube;
               ^
DETAIL:  Different point dimensions in (1,2) and (1,2,3).
SELECT '(1),(2),'::cube AS cube; -- 2
ERROR:  invalid input syntax for cube
LINE 1: SELECT '(1),(2),'::cube AS cube;
               ^
DETAIL:  syntax error at or near ","
SELECT '(1,2,3),(2,3)'::cube AS cube; -- 3
ERROR:  invalid input syntax for cube
LINE 1: SELECT '(1,2,3),(2,3)'::cube AS cube;
               ^
DETAIL:  Different point dimensions in (1,2,3) and (2,3).
SELECT '(1,2),(1,2,3)'::cube AS cube; -- 3
ERROR:  invalid input syntax for cube
LINE 1: SELECT '(1,2),(1,2,3)'::cube AS cube;
               ^
DETAIL:  Different point dimensions in (1,2) and (1,2,3).
SELECT '(1,2,3)ab'::cube AS cube; -- 4
ERROR:  invalid input syntax for cube
LINE 1: SELECT '(1,2,3)ab'::cube AS cube;
               ^
DETAIL:  syntax error at or near "a"
SELECT '(1,2,3)a'::cube AS cube; -- 5
ERROR:  invalid input syntax for cube
LINE 1: SELECT '(1,2,3)a'::cube AS cube;
               ^
DETAIL:  syntax error at or near "a"
SELECT '(1,2)('::cube AS cube; -- 5
ERROR:  invalid input syntax for cube
LINE 1: SELECT '(1,2)('::cube AS cube;
               ^
DETAIL:  syntax error at or near "("
SELECT '1,2ab'::cube AS cube; -- 6
ERROR:  invalid input syntax for cube
LINE 1: SELECT '1,2ab'::cube AS cube;
               ^
DETAIL:  syntax error at or near "a"
SELECT '1 e7'::cube AS cube; -- 6
ERROR:  invalid input syntax for cube
LINE 1: SELECT '1 e7'::cube AS cube;
               ^
DETAIL:  syntax error at or near "e"
SELECT '1,2a'::cube AS cube; -- 7
ERROR:  invalid input syntax for cube
LINE 1: SELECT '1,2a'::cube AS cube;
               ^
DETAIL:  syntax error at or near "a"
SELECT '1..2'::cube AS cube; -- 7
ERROR:  invalid input syntax for cube
LINE 1: SELECT '1..2'::cube AS cube;
               ^
DETAIL:  syntax error at or near ".2"
SELECT '-1e-700'::cube AS cube; -- out of range
ERROR:  "-1e-700" is out of range for type double precision
LINE 1: SELECT '-1e-700'::cube AS cube;
               ^
-- Also try it with non-error-throwing API
SELECT pg_input_is_valid('(1,2)', 'cube');
 pg_input_is_valid 
-------------------
 t
(1 row)

SELECT pg_input_is_valid('[(1),]', 'cube');
 pg_input_is_valid 
-------------------
 f
(1 row)

SELECT pg_input_is_valid('-1e-700', 'cube');
 pg_input_is_valid 
-------------------
 f
(1 row)

SELECT * FROM pg_input_error_info('-1e-700', 'cube');
                       message                       | detail | hint | sql_error_code 
-----------------------------------------------------+--------+------+----------------
 "-1e-700" is out of range for type double precision |        |      | 22003
(1 row)

--
-- Testing building cubes from float8 values
--
SELECT cube(0::float8);
 cube 
------
 (0)
(1 row)

SELECT cube(1::float8);
 cube 
------
 (1)
(1 row)

SELECT cube(1,2);
  cube   
---------
 (1),(2)
(1 row)

SELECT cube(cube(1,2),3);
     cube      
---------------
 (13),(23)
(1 row)

SELECT cube(cube(1,2),3,4);
     cube      
---------------
 (13),(24)
(1 row)

SELECT cube(cube(cube(1,2),3,4),5);
        cube         
---------------------
 (135),(245)
(1 row)

SELECT cube(cube(cube(1,2),3,4),5,6);
        cube         
---------------------
 (135),(246)
(1 row)

--
-- Test that the text -> cube cast was installed.
--
SELECT '(0)'::text::cube;
 cube 
------
 (0)
(1 row)

--
-- Test the float[] -> cube cast
--
SELECT cube('{0,1,2}'::float[], '{3,4,5}'::float[]);
        cube         
---------------------
 (012),(345)
(1 row)

SELECT cube('{0,1,2}'::float[], '{3}'::float[]);
ERROR:  UR and LL arrays must be of same length
SELECT cube(NULL::float[], '{3}'::float[]);
 cube 
------
 
(1 row)

SELECT cube('{0,1,2}'::float[]);
   cube    
-----------
 (012)
(1 row)

SELECT cube_subset(cube('(1,3,5),(6,7,8)'), ARRAY[3,2,1,1]);
        cube_subset        
---------------------------
 (5311),(8766)
(1 row)

SELECT cube_subset(cube('(1,3,5),(1,3,5)'), ARRAY[3,2,1,1]);
 cube_subset  
--------------
 (5311)
(1 row)

SELECT cube_subset(cube('(1,3,5),(6,7,8)'), ARRAY[4,0]);
ERROR:  Index out of bounds
SELECT cube_subset(cube('(6,7,8),(6,7,8)'), ARRAY[4,0]);
ERROR:  Index out of bounds
-- test for limits: this should pass
SELECT cube_subset(cube('(6,7,8),(6,7,8)'), array(SELECT 1 as a FROM generate_series(1,100)));
                                                                                                                                                 cube_subset                                                                                                                                                  
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 (6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666)
(1 row)

-- and this should fail
SELECT cube_subset(cube('(6,7,8),(6,7,8)'), array(SELECT 1 as a FROM generate_series(1,101)));
ERROR:  array is too long
DETAIL:  A cube cannot have more than 100 dimensions.
--
-- Test point processing
--
SELECT cube('(1,2),(1,2)'); -- cube_in
  cube  
--------
 (12)
(1 row)

SELECT cube('{0,1,2}'::float[], '{0,1,2}'::float[]); -- cube_a_f8_f8
   cube    
-----------
 (012)
(1 row)

SELECT cube('{5,6,7,8}'::float[]); -- cube_a_f8
     cube     
--------------
 (5678)
(1 row)

SELECT cube(1.37); -- cube_f8
  cube  
--------
 (1.37)
(1 row)

SELECT cube(1.371.37); -- cube_f8_f8
  cube  
--------
 (1.37)
(1 row)

SELECT cube(cube(1,1), 42); -- cube_c_f8
  cube   
---------
 (142)
(1 row)

SELECT cube(cube(1,2), 42); -- cube_c_f8
      cube       
-----------------
 (142),(242)
(1 row)

SELECT cube(cube(1,1), 4242); -- cube_c_f8_f8
  cube   
---------
 (142)
(1 row)

SELECT cube(cube(1,1), 4224); -- cube_c_f8_f8
      cube       
-----------------
 (142),(124)
(1 row)

SELECT cube(cube(1,2), 4242); -- cube_c_f8_f8
      cube       
-----------------
 (142),(242)
(1 row)

SELECT cube(cube(1,2), 4224); -- cube_c_f8_f8
      cube       
-----------------
 (142),(224)
(1 row)

--
-- Testing limit of CUBE_MAX_DIM dimensions check in cube_in.
--
-- create too big cube from literal
select '(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)'::cube;
ERROR:  invalid input syntax for cube
LINE 1: select '(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0...
               ^
DETAIL:  A cube cannot have more than 100 dimensions.
select '(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)'::cube;
ERROR:  invalid input syntax for cube
LINE 1: select '(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0...
               ^
DETAIL:  A cube cannot have more than 100 dimensions.
-- from an array
select cube(array(SELECT 0 as a FROM generate_series(1,101)));
ERROR:  array is too long
DETAIL:  A cube cannot have more than 100 dimensions.
select cube(array(SELECT 0 as a FROM generate_series(1,101)),array(SELECT 0 as a FROM generate_series(1,101)));
ERROR:  can't extend cube
DETAIL:  A cube cannot have more than 100 dimensions.
-- extend cube beyond limit
-- this should work
select cube(array(SELECT 0 as a FROM generate_series(1,100)));
                                                                                                                                                     cube                                                                                                                                                     
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 (0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)
(1 row)

select cube(array(SELECT 0 as a FROM generate_series(1,100)),array(SELECT 0 as a FROM generate_series(1,100)));
                                                                                                                                                     cube                                                                                                                                                     
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 (0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)
(1 row)

-- this should fail
select cube(cube(array(SELECT 0 as a FROM generate_series(1,100))), 0);
ERROR:  can't extend cube
DETAIL:  A cube cannot have more than 100 dimensions.
select cube(cube(array(SELECT 0 as a FROM generate_series(1,100)),array(SELECT 0 as a FROM generate_series(1,100))), 00);
ERROR:  can't extend cube
DETAIL:  A cube cannot have more than 100 dimensions.
--
-- testing the  operators
--
-- equality/inequality:
--
SELECT '2433.20'::cube    =  '2433.20'::cube AS bool;
 bool 
------
 t
(1 row)

SELECT '2433.20'::cube    != '2433.20'::cube AS bool;
 bool 
------
 f
(1 row)

SELECT '2433.20'::cube    =  '2433.21'::cube AS bool;
 bool 
------
 f
(1 row)

SELECT '2433.20'::cube    != '2433.21'::cube AS bool;
 bool 
------
 t
(1 row)

SELECT '(2,0),(3,1)'::cube  =  '(2,0,0,0,0),(3,1,0,0,0)'::cube AS bool;
 bool 
------
 f
(1 row)

SELECT '(2,0),(3,1)'::cube  =  '(2,0,0,0,0),(3,1,0,0,1)'::cube AS bool;
 bool 
------
 f
(1 row)

-- "lower than" / "greater than"
-- (these operators are not useful for anything but ordering)
--
SELECT '1'::cube   > '2'::cube AS bool;
 bool 
------
 f
(1 row)

SELECT '1'::cube   < '2'::cube AS bool;
 bool 
------
 t
(1 row)

SELECT '1,1'::cube > '1,2'::cube AS bool;
 bool 
------
 f
(1 row)

SELECT '1,1'::cube < '1,2'::cube AS bool;
 bool 
------
 t
(1 row)

SELECT '(2,0),(3,1)'::cube             > '(2,0,0,0,0),(3,1,0,0,1)'::cube AS bool;
 bool 
------
 f
(1 row)

SELECT '(2,0),(3,1)'::cube             < '(2,0,0,0,0),(3,1,0,0,1)'::cube AS bool;
 bool 
------
 t
(1 row)

SELECT '(2,0),(3,1)'::cube             > '(2,0,0,0,1),(3,1,0,0,0)'::cube AS bool;
 bool 
------
 f
(1 row)

SELECT '(2,0),(3,1)'::cube             < '(2,0,0,0,1),(3,1,0,0,0)'::cube AS bool;
 bool 
------
 t
(1 row)

SELECT '(2,0),(3,1)'::cube             > '(2,0,0,0,0),(3,1,0,0,0)'::cube AS bool;
 bool 
------
 f
(1 row)

SELECT '(2,0),(3,1)'::cube             < '(2,0,0,0,0),(3,1,0,0,0)'::cube AS bool;
 bool 
------
 t
(1 row)

SELECT '(2,0,0,0,0),(3,1,0,0,1)'::cube > '(2,0),(3,1)'::cube AS bool;
 bool 
------
 t
(1 row)

SELECT '(2,0,0,0,0),(3,1,0,0,1)'::cube < '(2,0),(3,1)'::cube AS bool;
 bool 
------
 f
(1 row)

SELECT '(2,0,0,0,1),(3,1,0,0,0)'::cube > '(2,0),(3,1)'::cube AS bool;
 bool 
------
 t
(1 row)

SELECT '(2,0,0,0,1),(3,1,0,0,0)'::cube < '(2,0),(3,1)'::cube AS bool;
 bool 
------
 f
(1 row)

SELECT '(2,0,0,0,0),(3,1,0,0,0)'::cube > '(2,0),(3,1)'::cube AS bool;
 bool 
------
 t
(1 row)

SELECT '(2,0,0,0,0),(3,1,0,0,0)'::cube < '(2,0),(3,1)'::cube AS bool;
 bool 
------
 f
(1 row)

-- "overlap"
--
SELECT '1'::cube && '1'::cube AS bool;
 bool 
------
 t
(1 row)

SELECT '1'::cube && '2'::cube AS bool;
 bool 
------
 f
(1 row)

SELECT '[(-1,-1,-1),(1,1,1)]'::cube && '0'::cube AS bool;
 bool 
------
 t
(1 row)

SELECT '[(-1,-1,-1),(1,1,1)]'::cube && '1'::cube AS bool;
 bool 
------
 t
(1 row)

SELECT '[(-1,-1,-1),(1,1,1)]'::cube && '1,1,1'::cube AS bool;
 bool 
------
 t
(1 row)

SELECT '[(-1,-1,-1),(1,1,1)]'::cube && '[(1,1,1),(2,2,2)]'::cube AS bool;
 bool 
------
 t
(1 row)

SELECT '[(-1,-1,-1),(1,1,1)]'::cube && '[(1,1),(2,2)]'::cube AS bool;
 bool 
------
 t
(1 row)

SELECT '[(-1,-1,-1),(1,1,1)]'::cube && '[(2,1,1),(2,2,2)]'::cube AS bool;
 bool 
------
 f
(1 row)

-- "contained in" (the left operand is the cube entirely enclosed by
-- the right operand):
--
SELECT '0'::cube                 <@ '0'::cube                        AS bool;
 bool 
------
 t
(1 row)

SELECT '0,0,0'::cube             <@ '0,0,0'::cube                    AS bool;
 bool 
------
 t
(1 row)

SELECT '0,0'::cube               <@ '0,0,1'::cube                    AS bool;
 bool 
------
 t
(1 row)

SELECT '0,0,0'::cube             <@ '0,0,1'::cube                    AS bool;
 bool 
------
 f
(1 row)

SELECT '1,0,0'::cube             <@ '0,0,1'::cube                    AS bool;
 bool 
------
 f
(1 row)

SELECT '(1,0,0),(0,0,1)'::cube   <@ '(1,0,0),(0,0,1)'::cube          AS bool;
 bool 
------
 t
(1 row)

SELECT '(1,0,0),(0,0,1)'::cube   <@ '(-1,-1,-1),(1,1,1)'::cube       AS bool;
 bool 
------
 t
(1 row)

SELECT '(1,0,0),(0,0,1)'::cube   <@ '(-1,-1,-1,-1),(1,1,1,1)'::cube  AS bool;
 bool 
------
 t
(1 row)

SELECT '0'::cube                 <@ '(-1),(1)'::cube                 AS bool;
 bool 
------
 t
(1 row)

SELECT '1'::cube                 <@ '(-1),(1)'::cube                 AS bool;
 bool 
------
 t
(1 row)

SELECT '-1'::cube                <@ '(-1),(1)'::cube                 AS bool;
 bool 
------
 t
(1 row)

SELECT '(-1),(1)'::cube          <@ '(-1),(1)'::cube                 AS bool;
 bool 
------
 t
(1 row)

SELECT '(-1),(1)'::cube          <@ '(-1,-1),(1,1)'::cube            AS bool;
 bool 
------
 t
(1 row)

SELECT '(-2),(1)'::cube          <@ '(-1),(1)'::cube                 AS bool;
 bool 
------
 f
(1 row)

SELECT '(-2),(1)'::cube          <@ '(-1,-1),(1,1)'::cube            AS bool;
 bool 
------
 f
(1 row)

-- "contains" (the left operand is the cube that entirely encloses the
-- right operand)
--
SELECT '0'::cube                        @> '0'::cube                 AS bool;
 bool 
------
 t
(1 row)

SELECT '0,0,0'::cube                    @> '0,0,0'::cube             AS bool;
 bool 
------
 t
(1 row)

SELECT '0,0,1'::cube                    @> '0,0'::cube               AS bool;
 bool 
------
 t
(1 row)

SELECT '0,0,1'::cube                    @> '0,0,0'::cube             AS bool;
 bool 
------
 f
(1 row)

SELECT '0,0,1'::cube                    @> '1,0,0'::cube             AS bool;
 bool 
------
 f
(1 row)

SELECT '(1,0,0),(0,0,1)'::cube          @> '(1,0,0),(0,0,1)'::cube   AS bool;
 bool 
------
 t
(1 row)

SELECT '(-1,-1,-1),(1,1,1)'::cube       @> '(1,0,0),(0,0,1)'::cube   AS bool;
 bool 
------
 t
(1 row)

SELECT '(-1,-1,-1,-1),(1,1,1,1)'::cube  @> '(1,0,0),(0,0,1)'::cube   AS bool;
 bool 
------
 t
(1 row)

SELECT '(-1),(1)'::cube                 @> '0'::cube                 AS bool;
 bool 
------
 t
(1 row)

SELECT '(-1),(1)'::cube                 @> '1'::cube                 AS bool;
 bool 
------
 t
(1 row)

SELECT '(-1),(1)'::cube                 @> '-1'::cube                AS bool;
 bool 
------
 t
(1 row)

SELECT '(-1),(1)'::cube                 @> '(-1),(1)'::cube          AS bool;
 bool 
------
 t
(1 row)

SELECT '(-1,-1),(1,1)'::cube            @> '(-1),(1)'::cube          AS bool;
 bool 
------
 t
(1 row)

SELECT '(-1),(1)'::cube                 @> '(-2),(1)'::cube          AS bool;
 bool 
------
 f
(1 row)

SELECT '(-1,-1),(1,1)'::cube            @> '(-2),(1)'::cube          AS bool;
 bool 
------
 f
(1 row)

-- Test of distance function
--
SELECT cube_distance('(0)'::cube,'(2,2,2,2)'::cube);
 cube_distance 
---------------
             4
(1 row)

SELECT cube_distance('(0)'::cube,'(.3,.4)'::cube);
 cube_distance 
---------------
           0.5
(1 row)

SELECT cube_distance('(2,3,4)'::cube,'(2,3,4)'::cube);
 cube_distance 
---------------
             0
(1 row)

SELECT cube_distance('(42,42,42,42)'::cube,'(137,137,137,137)'::cube);
 cube_distance 
---------------
           190
(1 row)

SELECT cube_distance('(42,42,42)'::cube,'(137,137)'::cube);
   cube_distance    
--------------------
 140.76221083799445
(1 row)

-- Test of cube function (text to cube)
--
SELECT cube('(1,1.2)'::text);
   cube   
----------
 (11.2)
(1 row)

SELECT cube(NULL);
 cube 
------
 
(1 row)

-- Test of cube_dim function (dimensions stored in cube)
--
SELECT cube_dim('(0)'::cube);
 cube_dim 
----------
        1
(1 row)

SELECT cube_dim('(0,0)'::cube);
 cube_dim 
----------
        2
(1 row)

SELECT cube_dim('(0,0,0)'::cube);
 cube_dim 
----------
        3
(1 row)

SELECT cube_dim('(42,42,42),(42,42,42)'::cube);
 cube_dim 
----------
        3
(1 row)

SELECT cube_dim('(4,8,15,16,23),(4,8,15,16,23)'::cube);
 cube_dim 
----------
        5
(1 row)

-- Test of cube_ll_coord function (retrieves LL coordinate values)
--
SELECT cube_ll_coord('(-1,1),(2,-2)'::cube, 1);
 cube_ll_coord 
---------------
            -1
(1 row)

SELECT cube_ll_coord('(-1,1),(2,-2)'::cube, 2);
 cube_ll_coord 
---------------
            -2
(1 row)

SELECT cube_ll_coord('(-1,1),(2,-2)'::cube, 3);
 cube_ll_coord 
---------------
             0
(1 row)

SELECT cube_ll_coord('(1,2),(1,2)'::cube, 1);
 cube_ll_coord 
---------------
             1
(1 row)

SELECT cube_ll_coord('(1,2),(1,2)'::cube, 2);
 cube_ll_coord 
---------------
             2
(1 row)

SELECT cube_ll_coord('(1,2),(1,2)'::cube, 3);
 cube_ll_coord 
---------------
             0
(1 row)

SELECT cube_ll_coord('(42,137)'::cube, 1);
 cube_ll_coord 
---------------
            42
(1 row)

SELECT cube_ll_coord('(42,137)'::cube, 2);
 cube_ll_coord 
---------------
           137
(1 row)

SELECT cube_ll_coord('(42,137)'::cube, 3);
 cube_ll_coord 
---------------
             0
(1 row)

-- Test of cube_ur_coord function (retrieves UR coordinate values)
--
SELECT cube_ur_coord('(-1,1),(2,-2)'::cube, 1);
 cube_ur_coord 
---------------
             2
(1 row)

SELECT cube_ur_coord('(-1,1),(2,-2)'::cube, 2);
 cube_ur_coord 
---------------
             1
(1 row)

SELECT cube_ur_coord('(-1,1),(2,-2)'::cube, 3);
 cube_ur_coord 
---------------
             0
(1 row)

SELECT cube_ur_coord('(1,2),(1,2)'::cube, 1);
 cube_ur_coord 
---------------
             1
(1 row)

SELECT cube_ur_coord('(1,2),(1,2)'::cube, 2);
 cube_ur_coord 
---------------
             2
(1 row)

SELECT cube_ur_coord('(1,2),(1,2)'::cube, 3);
 cube_ur_coord 
---------------
             0
(1 row)

SELECT cube_ur_coord('(42,137)'::cube, 1);
 cube_ur_coord 
---------------
            42
(1 row)

SELECT cube_ur_coord('(42,137)'::cube, 2);
 cube_ur_coord 
---------------
           137
(1 row)

SELECT cube_ur_coord('(42,137)'::cube, 3);
 cube_ur_coord 
---------------
             0
(1 row)

-- Test of cube_is_point
--
SELECT cube_is_point('(0)'::cube);
 cube_is_point 
---------------
 t
(1 row)

SELECT cube_is_point('(0,1,2)'::cube);
 cube_is_point 
---------------
 t
(1 row)

SELECT cube_is_point('(0,1,2),(0,1,2)'::cube);
 cube_is_point 
---------------
 t
(1 row)

SELECT cube_is_point('(0,1,2),(-1,1,2)'::cube);
 cube_is_point 
---------------
 f
(1 row)

SELECT cube_is_point('(0,1,2),(0,-1,2)'::cube);
 cube_is_point 
---------------
 f
(1 row)

SELECT cube_is_point('(0,1,2),(0,1,-2)'::cube);
 cube_is_point 
---------------
 f
(1 row)

-- Test of cube_enlarge (enlarging and shrinking cubes)
--
SELECT cube_enlarge('(0)'::cube, 00);
 cube_enlarge 
--------------
 (0)
(1 row)

SELECT cube_enlarge('(0)'::cube, 01);
 cube_enlarge 
--------------
 (0)
(1 row)

SELECT cube_enlarge('(0)'::cube, 02);
 cube_enlarge 
--------------
 (0)
(1 row)

SELECT cube_enlarge('(2),(-2)'::cube, 04);
 cube_enlarge 
--------------
 (-2),(2)
(1 row)

SELECT cube_enlarge('(0)'::cube, 10);
 cube_enlarge 
--------------
 (-1),(1)
(1 row)

SELECT cube_enlarge('(0)'::cube, 11);
 cube_enlarge 
--------------
 (-1),(1)
(1 row)

SELECT cube_enlarge('(0)'::cube, 12);
  cube_enlarge   
-----------------
 (-1, -1),(11)
(1 row)

SELECT cube_enlarge('(2),(-2)'::cube, 14);
         cube_enlarge          
-------------------------------
 (-3, -1, -1, -1),(3111)
(1 row)

SELECT cube_enlarge('(0)'::cube, -10);
 cube_enlarge 
--------------
 (0)
(1 row)

SELECT cube_enlarge('(0)'::cube, -11);
 cube_enlarge 
--------------
 (0)
(1 row)

SELECT cube_enlarge('(0)'::cube, -12);
 cube_enlarge 
--------------
 (0)
(1 row)

SELECT cube_enlarge('(2),(-2)'::cube, -14);
 cube_enlarge 
--------------
 (-1),(1)
(1 row)

SELECT cube_enlarge('(0,0,0)'::cube, 10);
      cube_enlarge      
------------------------
 (-1, -1, -1),(111)
(1 row)

SELECT cube_enlarge('(0,0,0)'::cube, 12);
      cube_enlarge      
------------------------
 (-1, -1, -1),(111)
(1 row)

SELECT cube_enlarge('(2,-2),(-3,7)'::cube, 12);
  cube_enlarge   
-----------------
 (-4, -3),(38)
(1 row)

SELECT cube_enlarge('(2,-2),(-3,7)'::cube, 32);
   cube_enlarge   
------------------
 (-6, -5),(510)
(1 row)

SELECT cube_enlarge('(2,-2),(-3,7)'::cube, -12);
  cube_enlarge   
-----------------
 (-2, -1),(16)
(1 row)

SELECT cube_enlarge('(2,-2),(-3,7)'::cube, -32);
    cube_enlarge     
---------------------
 (-0.51),(-0.54)
(1 row)

SELECT cube_enlarge('(42,-23,-23),(42,23,23)'::cube, -235);
 cube_enlarge 
--------------
 (4200)
(1 row)

SELECT cube_enlarge('(42,-23,-23),(42,23,23)'::cube, -245);
 cube_enlarge 
--------------
 (4200)
(1 row)

-- Test of cube_union (MBR for two cubes)
--
SELECT cube_union('(1,2),(3,4)'::cube, '(5,6,7),(8,9,10)'::cube);
      cube_union      
----------------------
 (120),(8910)
(1 row)

SELECT cube_union('(1,2)'::cube, '(4,2,0,0)'::cube);
        cube_union         
---------------------------
 (1200),(4200)
(1 row)

SELECT cube_union('(1,2),(1,2)'::cube, '(4,2),(4,2)'::cube);
  cube_union   
---------------
 (12),(42)
(1 row)

SELECT cube_union('(1,2),(1,2)'::cube, '(1,2),(1,2)'::cube);
 cube_union 
------------
 (12)
(1 row)

SELECT cube_union('(1,2),(1,2)'::cube, '(1,2,0),(1,2,0)'::cube);
 cube_union 
------------
 (120)
(1 row)

-- Test of cube_inter
--
SELECT cube_inter('(1,2),(10,11)'::cube, '(3,4), (16,15)'::cube); -- intersects
   cube_inter    
-----------------
 (34),(1011)
(1 row)

SELECT cube_inter('(1,2),(10,11)'::cube, '(3,4), (6,5)'::cube); -- includes
  cube_inter   
---------------
 (34),(65)
(1 row)

SELECT cube_inter('(1,2),(10,11)'::cube, '(13,14), (16,15)'::cube); -- no intersection
    cube_inter     
-------------------
 (1314),(1011)
(1 row)

SELECT cube_inter('(1,2),(10,11)'::cube, '(3,14), (16,15)'::cube); -- no intersection, but one dimension intersects
    cube_inter    
------------------
 (314),(1011)
(1 row)

SELECT cube_inter('(1,2),(10,11)'::cube, '(10,11), (16,15)'::cube); -- point intersection
 cube_inter 
------------
 (1011)
(1 row)

SELECT cube_inter('(1,2,3)'::cube, '(1,2,3)'::cube); -- point args
 cube_inter 
------------
 (123)
(1 row)

SELECT cube_inter('(1,2,3)'::cube, '(5,6,3)'::cube); -- point args
     cube_inter      
---------------------
 (563),(123)
(1 row)

-- Test of cube_size
--
SELECT cube_size('(4,8),(15,16)'::cube);
 cube_size 
-----------
        88
(1 row)

SELECT cube_size('(42,137)'::cube);
 cube_size 
-----------
         0
(1 row)

-- Test of distances (euclidean distance may not be bit-exact)
--
SET extra_float_digits = 0;
SELECT cube_distance('(1,1)'::cube, '(4,5)'::cube);
 cube_distance 
---------------
             5
(1 row)

SELECT '(1,1)'::cube <-> '(4,5)'::cube as d_e;
 d_e 
-----
   5
(1 row)

RESET extra_float_digits;
SELECT distance_chebyshev('(1,1)'::cube, '(4,5)'::cube);
 distance_chebyshev 
--------------------
                  4
(1 row)

SELECT '(1,1)'::cube <=> '(4,5)'::cube as d_c;
 d_c 
-----
   4
(1 row)

SELECT distance_taxicab('(1,1)'::cube, '(4,5)'::cube);
 distance_taxicab 
------------------
                7
(1 row)

SELECT '(1,1)'::cube <#> '(4,5)'::cube as d_t;
 d_t 
-----
   7
(1 row)

-- zero for overlapping
SELECT cube_distance('(2,2),(10,10)'::cube, '(0,0),(5,5)'::cube);
 cube_distance 
---------------
             0
(1 row)

SELECT distance_chebyshev('(2,2),(10,10)'::cube, '(0,0),(5,5)'::cube);
 distance_chebyshev 
--------------------
                  0
(1 row)

SELECT distance_taxicab('(2,2),(10,10)'::cube, '(0,0),(5,5)'::cube);
 distance_taxicab 
------------------
                0
(1 row)

-- coordinate access
SELECT cube(array[10,20,30], array[40,50,60])->1;
 ?column? 
----------
       10
(1 row)

SELECT cube(array[40,50,60], array[10,20,30])->1;
 ?column? 
----------
       40
(1 row)

SELECT cube(array[10,20,30], array[40,50,60])->6;
 ?column? 
----------
       60
(1 row)

SELECT cube(array[10,20,30], array[40,50,60])->0;
ERROR:  cube index 0 is out of bounds
SELECT cube(array[10,20,30], array[40,50,60])->7;
ERROR:  cube index 7 is out of bounds
SELECT cube(array[10,20,30], array[40,50,60])->-1;
ERROR:  cube index -1 is out of bounds
SELECT cube(array[10,20,30], array[40,50,60])->-6;
ERROR:  cube index -6 is out of bounds
SELECT cube(array[10,20,30])->3;
 ?column? 
----------
       30
(1 row)

SELECT cube(array[10,20,30])->6;
 ?column? 
----------
       30
(1 row)

SELECT cube(array[10,20,30])->-6;
ERROR:  cube index -6 is out of bounds
-- "normalized" coordinate access
SELECT cube(array[10,20,30], array[40,50,60])~>1;
 ?column? 
----------
       10
(1 row)

SELECT cube(array[40,50,60], array[10,20,30])~>1;
 ?column? 
----------
       10
(1 row)

SELECT cube(array[10,20,30], array[40,50,60])~>2;
 ?column? 
----------
       40
(1 row)

SELECT cube(array[40,50,60], array[10,20,30])~>2;
 ?column? 
----------
       40
(1 row)

SELECT cube(array[10,20,30], array[40,50,60])~>3;
 ?column? 
----------
       20
(1 row)

SELECT cube(array[40,50,60], array[10,20,30])~>3;
 ?column? 
----------
       20
(1 row)

SELECT cube(array[40,50,60], array[10,20,30])~>0;
ERROR:  zero cube index is not defined
SELECT cube(array[40,50,60], array[10,20,30])~>4;
 ?column? 
----------
       50
(1 row)

SELECT cube(array[40,50,60], array[10,20,30])~>(-1);
 ?column? 
----------
      -10
(1 row)

-- Load some example data and build the index
--
CREATE TABLE test_cube (c cube);
\copy test_cube from 'data/test_cube.data'
CREATE INDEX test_cube_ix ON test_cube USING gist (c);
SELECT * FROM test_cube WHERE c && '(3000,1000),(0,0)' ORDER BY c;
            c             
--------------------------
 (337455),(240359)
 (759187),(662163)
 (1444403),(1346344)
 (15941043),(1517971)
 (2424160),(242481)
(5 rows)

-- Test sorting
SELECT * FROM test_cube WHERE c && '(3000,1000),(0,0)' GROUP BY c ORDER BY c;
            c             
--------------------------
 (337455),(240359)
 (759187),(662163)
 (1444403),(1346344)
 (15941043),(1517971)
 (2424160),(242481)
(5 rows)

-- Test index-only scans
SET enable_bitmapscan = false;
EXPLAIN (COSTS OFF)
SELECT c FROM test_cube WHERE c <@ '(3000,1000),(0,0)' ORDER BY c;
                       QUERY PLAN                       
--------------------------------------------------------
 Sort
   Sort Key: c
   ->  Index Only Scan using test_cube_ix on test_cube
         Index Cond: (c <@ '(30001000),(00)'::cube)
(4 rows)

SELECT c FROM test_cube WHERE c <@ '(3000,1000),(0,0)' ORDER BY c;
            c            
-------------------------
 (337455),(240359)
 (759187),(662163)
 (1444403),(1346344)
 (2424160),(242481)
(4 rows)

RESET enable_bitmapscan;
-- Test kNN
INSERT INTO test_cube VALUES ('(1,1)'), ('(100000)'), ('(0100000)'); -- Some corner cases
SET enable_seqscan = false;
-- Test different metrics
SET extra_float_digits = 0;
SELECT *, c <-> '(100100),(500500)'::cube as dist FROM test_cube ORDER BY c <-> '(100100),(500500)'::cube LIMIT 5;
            c            |       dist       
-------------------------+------------------
 (337455),(240359)   |                0
 (11)                  | 140.007142674936
 (759187),(662163)   |              162
 (9481201),(9071156) | 772.000647668122
 (1444403),(1346344) |              846
(5 rows)

RESET extra_float_digits;
SELECT *, c <=> '(100100),(500500)'::cube as dist FROM test_cube ORDER BY c <=> '(100100),(500500)'::cube LIMIT 5;
            c            | dist 
-------------------------+------
 (337455),(240359)   |    0
 (11)                  |   99
 (759187),(662163)   |  162
 (9481201),(9071156) |  656
 (1444403),(1346344) |  846
(5 rows)

SELECT *, c <#> '(100100),(500500)'::cube as dist FROM test_cube ORDER BY c <#> '(100100),(500500)'::cube LIMIT 5;
            c            | dist 
-------------------------+------
 (337455),(240359)   |    0
 (759187),(662163)   |  162
 (11)                  |  198
 (1444403),(1346344) |  846
 (3691457),(2781409) |  909
(5 rows)

-- Test sorting by coordinates
SELECT c~>1, c FROM test_cube ORDER BY c~>1 LIMIT 15; -- ascending by left bound
 ?column? |             c             
----------+---------------------------
        0 | (0100000)
        1 | (11)
        3 | (5438679),(338602)
       15 | (8310271),(1510265)
       64 | (12246832),(6446762)
       92 | (16717214),(9217184)
      107 | (16124465),(10724374)
      120 | (16226040),(12025963)
      138 | (1544019),(1383990)
      175 | (2591850),(1751820)
      179 | (20740886),(17940879)
      204 | (28849588),(20449571)
      226 | (27032616),(22632607)
      235 | (31831489),(23531404)
      240 | (337455),(240359)
(15 rows)

SELECT c~>2, c FROM test_cube ORDER BY c~>2 LIMIT 15; -- ascending by right bound
 ?column? |             c             
----------+---------------------------
        0 | (0100000)
        1 | (11)
       54 | (5438679),(338602)
       83 | (8310271),(1510265)
      122 | (12246832),(6446762)
      154 | (1544019),(1383990)
      161 | (16124465),(10724374)
      162 | (16226040),(12025963)
      167 | (16717214),(9217184)
      207 | (20740886),(17940879)
      259 | (2591850),(1751820)
      270 | (27029508),(26429440)
      270 | (27032616),(22632607)
      288 | (28849588),(20449571)
      318 | (31831489),(23531404)
(15 rows)

SELECT c~>3, c FROM test_cube ORDER BY c~>3 LIMIT 15; -- ascending by lower bound
 ?column? |             c             
----------+---------------------------
        0 | (100000)
        1 | (11)
        6 | (3033350),(302736)
       43 | (4330175),(4322743)
       51 | (19650142),(1963051)
       81 | (2424160),(242481)
      108 | (3449171),(3354108)
      109 | (18037155),(17941109)
      114 | (28511208),(28479114)
      118 | (19946217),(19941118)
      139 | (16906191),(16816139)
      163 | (759187),(662163)
      181 | (22684266),(22656181)
      213 | (24423255),(24360213)
      222 | (45989249),(45910222)
(15 rows)

SELECT c~>4, c FROM test_cube ORDER BY c~>4 LIMIT 15; -- ascending by upper bound
 ?column? |             c             
----------+---------------------------
        0 | (100000)
        1 | (11)
       50 | (3033350),(302736)
       75 | (4330175),(4322743)
      142 | (19650142),(1963051)
      155 | (18037155),(17941109)
      160 | (2424160),(242481)
      171 | (3449171),(3354108)
      187 | (759187),(662163)
      191 | (16906191),(16816139)
      208 | (28511208),(28479114)
      217 | (19946217),(19941118)
      249 | (45989249),(45910222)
      255 | (24423255),(24360213)
      266 | (22684266),(22656181)
(15 rows)

SELECT c~>(-1), c FROM test_cube ORDER BY c~>(-1) LIMIT 15; -- descending by left bound
 ?column? |               c               
----------+-------------------------------
  -100000 | (100000)
   -49951 | (5002749230),(4995149214)
   -49937 | (4998035004),(4993734963)
   -49927 | (499856436),(499276338)
   -49908 | (4999927218),(4990827176)
   -49905 | (499541340),(499051294)
   -49902 | (4994425163),(4990225153)
   -49898 | (4998134876),(4989834786)
   -49897 | (4995743390),(4989743384)
   -49848 | (4985318504),(4984818503)
   -49818 | (4990241752),(4981841746)
   -49810 | (4990730225),(4981030158)
   -49808 | (498435175),(498085145)
   -49805 | (4988724274),(4980524184)
   -49798 | (498477128),(497987067)
(15 rows)

SELECT c~>(-2), c FROM test_cube ORDER BY c~>(-2) LIMIT 15; -- descending by right bound
 ?column? |               c               
----------+-------------------------------
  -100000 | (100000)
   -50027 | (5002749230),(4995149214)
   -49999 | (4999927218),(4990827176)
   -49985 | (499856436),(499276338)
   -49981 | (4998134876),(4989834786)
   -49980 | (4998035004),(4993734963)
   -49957 | (4995743390),(4989743384)
   -49954 | (499541340),(499051294)
   -49944 | (4994425163),(4990225153)
   -49907 | (4990730225),(4981030158)
   -49902 | (4990241752),(4981841746)
   -49887 | (4988724274),(4980524184)
   -49853 | (4985318504),(4984818503)
   -49847 | (498477128),(497987067)
   -49843 | (498435175),(498085145)
(15 rows)

SELECT c~>(-3), c FROM test_cube ORDER BY c~>(-3) LIMIT 15; -- descending by lower bound
 ?column? |               c               
----------+-------------------------------
  -100000 | (0100000)
   -49992 | (3074650040),(3072749992)
   -49987 | (3631150073),(3625849987)
   -49934 | (353149962),(346349934)
   -49915 | (1795449975),(1786549915)
   -49914 | (216850012),(210849914)
   -49913 | (3128749923),(3123649913)
   -49885 | (2155149983),(2149249885)
   -49878 | (4392549912),(4388849878)
   -49849 | (1912849932),(1911249849)
   -49844 | (3826649852),(3823349844)
   -49836 | (1491349873),(1484949836)
   -49834 | (3759549849),(3758149834)
   -49830 | (4615149848),(4605849830)
   -49818 | (2926149910),(2924749818)
(15 rows)

SELECT c~>(-4), c FROM test_cube ORDER BY c~>(-4) LIMIT 15; -- descending by upper bound
 ?column? |               c               
----------+-------------------------------
  -100000 | (0100000)
   -50073 | (3631150073),(3625849987)
   -50040 | (3074650040),(3072749992)
   -50012 | (216850012),(210849914)
   -49983 | (2155149983),(2149249885)
   -49975 | (1795449975),(1786549915)
   -49962 | (353149962),(346349934)
   -49932 | (1912849932),(1911249849)
   -49923 | (3128749923),(3123649913)
   -49912 | (4392549912),(4388849878)
   -49910 | (2926149910),(2924749818)
   -49873 | (1491349873),(1484949836)
   -49858 | (2000749858),(1992149778)
   -49852 | (3826649852),(3823349844)
   -49849 | (3759549849),(3758149834)
(15 rows)

-- Same queries with sequential scan (should give the same results as above)
RESET enable_seqscan;
SET enable_indexscan = OFF;
SET extra_float_digits = 0;
SELECT *, c <-> '(100100),(500500)'::cube as dist FROM test_cube ORDER BY c <-> '(100100),(500500)'::cube LIMIT 5;
            c            |       dist       
-------------------------+------------------
 (337455),(240359)   |                0
 (11)                  | 140.007142674936
 (759187),(662163)   |              162
 (9481201),(9071156) | 772.000647668122
 (1444403),(1346344) |              846
(5 rows)

RESET extra_float_digits;
SELECT *, c <=> '(100100),(500500)'::cube as dist FROM test_cube ORDER BY c <=> '(100100),(500500)'::cube LIMIT 5;
            c            | dist 
-------------------------+------
 (337455),(240359)   |    0
 (11)                  |   99
 (759187),(662163)   |  162
 (9481201),(9071156) |  656
 (1444403),(1346344) |  846
(5 rows)

SELECT *, c <#> '(100100),(500500)'::cube as dist FROM test_cube ORDER BY c <#> '(100100),(500500)'::cube LIMIT 5;
            c            | dist 
-------------------------+------
 (337455),(240359)   |    0
 (759187),(662163)   |  162
 (11)                  |  198
 (1444403),(1346344) |  846
 (3691457),(2781409) |  909
(5 rows)

SELECT c~>1, c FROM test_cube ORDER BY c~>1 LIMIT 15; -- ascending by left bound
 ?column? |             c             
----------+---------------------------
        0 | (0100000)
        1 | (11)
        3 | (5438679),(338602)
       15 | (8310271),(1510265)
       64 | (12246832),(6446762)
       92 | (16717214),(9217184)
      107 | (16124465),(10724374)
      120 | (16226040),(12025963)
      138 | (1544019),(1383990)
      175 | (2591850),(1751820)
      179 | (20740886),(17940879)
      204 | (28849588),(20449571)
      226 | (27032616),(22632607)
      235 | (31831489),(23531404)
      240 | (337455),(240359)
(15 rows)

SELECT c~>2, c FROM test_cube ORDER BY c~>2 LIMIT 15; -- ascending by right bound
 ?column? |             c             
----------+---------------------------
        0 | (0100000)
        1 | (11)
       54 | (5438679),(338602)
       83 | (8310271),(1510265)
      122 | (12246832),(6446762)
      154 | (1544019),(1383990)
      161 | (16124465),(10724374)
      162 | (16226040),(12025963)
      167 | (16717214),(9217184)
      207 | (20740886),(17940879)
      259 | (2591850),(1751820)
      270 | (27029508),(26429440)
      270 | (27032616),(22632607)
      288 | (28849588),(20449571)
      318 | (31831489),(23531404)
(15 rows)

SELECT c~>3, c FROM test_cube ORDER BY c~>3 LIMIT 15; -- ascending by lower bound
 ?column? |             c             
----------+---------------------------
        0 | (100000)
        1 | (11)
        6 | (3033350),(302736)
       43 | (4330175),(4322743)
       51 | (19650142),(1963051)
       81 | (2424160),(242481)
      108 | (3449171),(3354108)
      109 | (18037155),(17941109)
      114 | (28511208),(28479114)
      118 | (19946217),(19941118)
      139 | (16906191),(16816139)
      163 | (759187),(662163)
      181 | (22684266),(22656181)
      213 | (24423255),(24360213)
      222 | (45989249),(45910222)
(15 rows)

SELECT c~>4, c FROM test_cube ORDER BY c~>4 LIMIT 15; -- ascending by upper bound
 ?column? |             c             
----------+---------------------------
        0 | (100000)
        1 | (11)
       50 | (3033350),(302736)
       75 | (4330175),(4322743)
      142 | (19650142),(1963051)
      155 | (18037155),(17941109)
      160 | (2424160),(242481)
      171 | (3449171),(3354108)
      187 | (759187),(662163)
      191 | (16906191),(16816139)
      208 | (28511208),(28479114)
      217 | (19946217),(19941118)
      249 | (45989249),(45910222)
      255 | (24423255),(24360213)
      266 | (22684266),(22656181)
(15 rows)

SELECT c~>(-1), c FROM test_cube ORDER BY c~>(-1) LIMIT 15; -- descending by left bound
 ?column? |               c               
----------+-------------------------------
  -100000 | (100000)
   -49951 | (5002749230),(4995149214)
   -49937 | (4998035004),(4993734963)
   -49927 | (499856436),(499276338)
   -49908 | (4999927218),(4990827176)
   -49905 | (499541340),(499051294)
   -49902 | (4994425163),(4990225153)
   -49898 | (4998134876),(4989834786)
   -49897 | (4995743390),(4989743384)
   -49848 | (4985318504),(4984818503)
   -49818 | (4990241752),(4981841746)
   -49810 | (4990730225),(4981030158)
   -49808 | (498435175),(498085145)
   -49805 | (4988724274),(4980524184)
   -49798 | (498477128),(497987067)
(15 rows)

SELECT c~>(-2), c FROM test_cube ORDER BY c~>(-2) LIMIT 15; -- descending by right bound
 ?column? |               c               
----------+-------------------------------
  -100000 | (100000)
   -50027 | (5002749230),(4995149214)
   -49999 | (4999927218),(4990827176)
   -49985 | (499856436),(499276338)
   -49981 | (4998134876),(4989834786)
   -49980 | (4998035004),(4993734963)
   -49957 | (4995743390),(4989743384)
   -49954 | (499541340),(499051294)
   -49944 | (4994425163),(4990225153)
   -49907 | (4990730225),(4981030158)
   -49902 | (4990241752),(4981841746)
   -49887 | (4988724274),(4980524184)
   -49853 | (4985318504),(4984818503)
   -49847 | (498477128),(497987067)
   -49843 | (498435175),(498085145)
(15 rows)

SELECT c~>(-3), c FROM test_cube ORDER BY c~>(-3) LIMIT 15; -- descending by lower bound
 ?column? |               c               
----------+-------------------------------
  -100000 | (0100000)
   -49992 | (3074650040),(3072749992)
   -49987 | (3631150073),(3625849987)
   -49934 | (353149962),(346349934)
   -49915 | (1795449975),(1786549915)
   -49914 | (216850012),(210849914)
   -49913 | (3128749923),(3123649913)
   -49885 | (2155149983),(2149249885)
   -49878 | (4392549912),(4388849878)
   -49849 | (1912849932),(1911249849)
   -49844 | (3826649852),(3823349844)
   -49836 | (1491349873),(1484949836)
   -49834 | (3759549849),(3758149834)
   -49830 | (4615149848),(4605849830)
   -49818 | (2926149910),(2924749818)
(15 rows)

SELECT c~>(-4), c FROM test_cube ORDER BY c~>(-4) LIMIT 15; -- descending by upper bound
 ?column? |               c               
----------+-------------------------------
  -100000 | (0100000)
   -50073 | (3631150073),(3625849987)
   -50040 | (3074650040),(3072749992)
   -50012 | (216850012),(210849914)
   -49983 | (2155149983),(2149249885)
   -49975 | (1795449975),(1786549915)
   -49962 | (353149962),(346349934)
   -49932 | (1912849932),(1911249849)
   -49923 | (3128749923),(3123649913)
   -49912 | (4392549912),(4388849878)
   -49910 | (2926149910),(2924749818)
   -49873 | (1491349873),(1484949836)
   -49858 | (2000749858),(1992149778)
   -49852 | (3826649852),(3823349844)
   -49849 | (3759549849),(3758149834)
(15 rows)

RESET enable_indexscan;

[Dauer der Verarbeitung: 0.33 Sekunden, vorverarbeitet 2026-08-08]

                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=141584
#Domains=738142