~ubuntu-branches/ubuntu/precise/postgresql-9.1/precise-security

« back to all changes in this revision

Viewing changes to contrib/cube/expected/cube_3.out

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--
 
2
--  Test cube datatype
 
3
--
 
4
CREATE EXTENSION cube;
 
5
--
 
6
-- testing the input and output functions
 
7
--
 
8
-- Any number (a one-dimensional point)
 
9
SELECT '1'::cube AS cube;
 
10
 cube 
 
11
------
 
12
 (1)
 
13
(1 row)
 
14
 
 
15
SELECT '-1'::cube AS cube;
 
16
 cube 
 
17
------
 
18
 (-1)
 
19
(1 row)
 
20
 
 
21
SELECT '1.'::cube AS cube;
 
22
 cube 
 
23
------
 
24
 (1)
 
25
(1 row)
 
26
 
 
27
SELECT '-1.'::cube AS cube;
 
28
 cube 
 
29
------
 
30
 (-1)
 
31
(1 row)
 
32
 
 
33
SELECT '.1'::cube AS cube;
 
34
 cube  
 
35
-------
 
36
 (0.1)
 
37
(1 row)
 
38
 
 
39
SELECT '-.1'::cube AS cube;
 
40
  cube  
 
41
--------
 
42
 (-0.1)
 
43
(1 row)
 
44
 
 
45
SELECT '1.0'::cube AS cube;
 
46
 cube 
 
47
------
 
48
 (1)
 
49
(1 row)
 
50
 
 
51
SELECT '-1.0'::cube AS cube;
 
52
 cube 
 
53
------
 
54
 (-1)
 
55
(1 row)
 
56
 
 
57
SELECT '1e27'::cube AS cube;
 
58
   cube   
 
59
----------
 
60
 (1e+027)
 
61
(1 row)
 
62
 
 
63
SELECT '-1e27'::cube AS cube;
 
64
   cube    
 
65
-----------
 
66
 (-1e+027)
 
67
(1 row)
 
68
 
 
69
SELECT '1.0e27'::cube AS cube;
 
70
   cube   
 
71
----------
 
72
 (1e+027)
 
73
(1 row)
 
74
 
 
75
SELECT '-1.0e27'::cube AS cube;
 
76
   cube    
 
77
-----------
 
78
 (-1e+027)
 
79
(1 row)
 
80
 
 
81
SELECT '1e+27'::cube AS cube;
 
82
   cube   
 
83
----------
 
84
 (1e+027)
 
85
(1 row)
 
86
 
 
87
SELECT '-1e+27'::cube AS cube;
 
88
   cube    
 
89
-----------
 
90
 (-1e+027)
 
91
(1 row)
 
92
 
 
93
SELECT '1.0e+27'::cube AS cube;
 
94
   cube   
 
95
----------
 
96
 (1e+027)
 
97
(1 row)
 
98
 
 
99
SELECT '-1.0e+27'::cube AS cube;
 
100
   cube    
 
101
-----------
 
102
 (-1e+027)
 
103
(1 row)
 
104
 
 
105
SELECT '1e-7'::cube AS cube;
 
106
   cube   
 
107
----------
 
108
 (1e-007)
 
109
(1 row)
 
110
 
 
111
SELECT '-1e-7'::cube AS cube;
 
112
   cube    
 
113
-----------
 
114
 (-1e-007)
 
115
(1 row)
 
116
 
 
117
SELECT '1.0e-7'::cube AS cube;
 
118
   cube   
 
119
----------
 
120
 (1e-007)
 
121
(1 row)
 
122
 
 
123
SELECT '-1.0e-7'::cube AS cube;
 
124
   cube    
 
125
-----------
 
126
 (-1e-007)
 
127
(1 row)
 
128
 
 
129
SELECT '1e-700'::cube AS cube;
 
130
 cube 
 
131
------
 
132
 (0)
 
133
(1 row)
 
134
 
 
135
SELECT '-1e-700'::cube AS cube;
 
136
 cube 
 
137
------
 
138
 (-0)
 
139
(1 row)
 
140
 
 
141
SELECT '1234567890123456'::cube AS cube;
 
142
          cube           
 
143
-------------------------
 
144
 (1.23456789012346e+015)
 
145
(1 row)
 
146
 
 
147
SELECT '+1234567890123456'::cube AS cube;
 
148
          cube           
 
149
-------------------------
 
150
 (1.23456789012346e+015)
 
151
(1 row)
 
152
 
 
153
SELECT '-1234567890123456'::cube AS cube;
 
154
           cube           
 
155
--------------------------
 
156
 (-1.23456789012346e+015)
 
157
(1 row)
 
158
 
 
159
SELECT '.1234567890123456'::cube AS cube;
 
160
        cube         
 
161
---------------------
 
162
 (0.123456789012346)
 
163
(1 row)
 
164
 
 
165
SELECT '+.1234567890123456'::cube AS cube;
 
166
        cube         
 
167
---------------------
 
168
 (0.123456789012346)
 
169
(1 row)
 
170
 
 
171
SELECT '-.1234567890123456'::cube AS cube;
 
172
         cube         
 
173
----------------------
 
174
 (-0.123456789012346)
 
175
(1 row)
 
176
 
 
177
-- simple lists (points)
 
178
SELECT '1,2'::cube AS cube;
 
179
  cube  
 
180
--------
 
181
 (1, 2)
 
182
(1 row)
 
183
 
 
184
SELECT '(1,2)'::cube AS cube;
 
185
  cube  
 
186
--------
 
187
 (1, 2)
 
188
(1 row)
 
189
 
 
190
SELECT '1,2,3,4,5'::cube AS cube;
 
191
      cube       
 
192
-----------------
 
193
 (1, 2, 3, 4, 5)
 
194
(1 row)
 
195
 
 
196
SELECT '(1,2,3,4,5)'::cube AS cube;
 
197
      cube       
 
198
-----------------
 
199
 (1, 2, 3, 4, 5)
 
200
(1 row)
 
201
 
 
202
-- double lists (cubes)
 
203
SELECT '(0),(0)'::cube AS cube;
 
204
 cube 
 
205
------
 
206
 (0)
 
207
(1 row)
 
208
 
 
209
SELECT '(0),(1)'::cube AS cube;
 
210
  cube   
 
211
---------
 
212
 (0),(1)
 
213
(1 row)
 
214
 
 
215
SELECT '[(0),(0)]'::cube AS cube;
 
216
 cube 
 
217
------
 
218
 (0)
 
219
(1 row)
 
220
 
 
221
SELECT '[(0),(1)]'::cube AS cube;
 
222
  cube   
 
223
---------
 
224
 (0),(1)
 
225
(1 row)
 
226
 
 
227
SELECT '(0,0,0,0),(0,0,0,0)'::cube AS cube;
 
228
     cube     
 
229
--------------
 
230
 (0, 0, 0, 0)
 
231
(1 row)
 
232
 
 
233
SELECT '(0,0,0,0),(1,0,0,0)'::cube AS cube;
 
234
           cube            
 
235
---------------------------
 
236
 (0, 0, 0, 0),(1, 0, 0, 0)
 
237
(1 row)
 
238
 
 
239
SELECT '[(0,0,0,0),(0,0,0,0)]'::cube AS cube;
 
240
     cube     
 
241
--------------
 
242
 (0, 0, 0, 0)
 
243
(1 row)
 
244
 
 
245
SELECT '[(0,0,0,0),(1,0,0,0)]'::cube AS cube;
 
246
           cube            
 
247
---------------------------
 
248
 (0, 0, 0, 0),(1, 0, 0, 0)
 
249
(1 row)
 
250
 
 
251
-- invalid input: parse errors
 
252
SELECT ''::cube AS cube;
 
253
ERROR:  bad cube representation
 
254
LINE 1: SELECT ''::cube AS cube;
 
255
               ^
 
256
DETAIL:  syntax error at end of input
 
257
SELECT 'ABC'::cube AS cube;
 
258
ERROR:  bad cube representation
 
259
LINE 1: SELECT 'ABC'::cube AS cube;
 
260
               ^
 
261
DETAIL:  syntax error at or near "A"
 
262
SELECT '()'::cube AS cube;
 
263
ERROR:  bad cube representation
 
264
LINE 1: SELECT '()'::cube AS cube;
 
265
               ^
 
266
DETAIL:  syntax error at or near ")"
 
267
SELECT '[]'::cube AS cube;
 
268
ERROR:  bad cube representation
 
269
LINE 1: SELECT '[]'::cube AS cube;
 
270
               ^
 
271
DETAIL:  syntax error at or near "]"
 
272
SELECT '[()]'::cube AS cube;
 
273
ERROR:  bad cube representation
 
274
LINE 1: SELECT '[()]'::cube AS cube;
 
275
               ^
 
276
DETAIL:  syntax error at or near ")"
 
277
SELECT '[(1)]'::cube AS cube;
 
278
ERROR:  bad cube representation
 
279
LINE 1: SELECT '[(1)]'::cube AS cube;
 
280
               ^
 
281
DETAIL:  syntax error at or near "]"
 
282
SELECT '[(1),]'::cube AS cube;
 
283
ERROR:  bad cube representation
 
284
LINE 1: SELECT '[(1),]'::cube AS cube;
 
285
               ^
 
286
DETAIL:  syntax error at or near "]"
 
287
SELECT '[(1),2]'::cube AS cube;
 
288
ERROR:  bad cube representation
 
289
LINE 1: SELECT '[(1),2]'::cube AS cube;
 
290
               ^
 
291
DETAIL:  syntax error at or near "2"
 
292
SELECT '[(1),(2),(3)]'::cube AS cube;
 
293
ERROR:  bad cube representation
 
294
LINE 1: SELECT '[(1),(2),(3)]'::cube AS cube;
 
295
               ^
 
296
DETAIL:  syntax error at or near ","
 
297
SELECT '1,'::cube AS cube;
 
298
ERROR:  bad cube representation
 
299
LINE 1: SELECT '1,'::cube AS cube;
 
300
               ^
 
301
DETAIL:  syntax error at end of input
 
302
SELECT '1,2,'::cube AS cube;
 
303
ERROR:  bad cube representation
 
304
LINE 1: SELECT '1,2,'::cube AS cube;
 
305
               ^
 
306
DETAIL:  syntax error at end of input
 
307
SELECT '1,,2'::cube AS cube;
 
308
ERROR:  bad cube representation
 
309
LINE 1: SELECT '1,,2'::cube AS cube;
 
310
               ^
 
311
DETAIL:  syntax error at or near ","
 
312
SELECT '(1,)'::cube AS cube;
 
313
ERROR:  bad cube representation
 
314
LINE 1: SELECT '(1,)'::cube AS cube;
 
315
               ^
 
316
DETAIL:  syntax error at or near ")"
 
317
SELECT '(1,2,)'::cube AS cube;
 
318
ERROR:  bad cube representation
 
319
LINE 1: SELECT '(1,2,)'::cube AS cube;
 
320
               ^
 
321
DETAIL:  syntax error at or near ")"
 
322
SELECT '(1,,2)'::cube AS cube;
 
323
ERROR:  bad cube representation
 
324
LINE 1: SELECT '(1,,2)'::cube AS cube;
 
325
               ^
 
326
DETAIL:  syntax error at or near ","
 
327
-- invalid input: semantic errors and trailing garbage
 
328
SELECT '[(1),(2)],'::cube AS cube; -- 0
 
329
ERROR:  bad cube representation
 
330
LINE 1: SELECT '[(1),(2)],'::cube AS cube;
 
331
               ^
 
332
DETAIL:  syntax error at or near ","
 
333
SELECT '[(1,2,3),(2,3)]'::cube AS cube; -- 1
 
334
ERROR:  bad cube representation
 
335
LINE 1: SELECT '[(1,2,3),(2,3)]'::cube AS cube;
 
336
               ^
 
337
DETAIL:  Different point dimensions in (1,2,3) and (2,3).
 
338
SELECT '[(1,2),(1,2,3)]'::cube AS cube; -- 1
 
339
ERROR:  bad cube representation
 
340
LINE 1: SELECT '[(1,2),(1,2,3)]'::cube AS cube;
 
341
               ^
 
342
DETAIL:  Different point dimensions in (1,2) and (1,2,3).
 
343
SELECT '(1),(2),'::cube AS cube; -- 2
 
344
ERROR:  bad cube representation
 
345
LINE 1: SELECT '(1),(2),'::cube AS cube;
 
346
               ^
 
347
DETAIL:  syntax error at or near ","
 
348
SELECT '(1,2,3),(2,3)'::cube AS cube; -- 3
 
349
ERROR:  bad cube representation
 
350
LINE 1: SELECT '(1,2,3),(2,3)'::cube AS cube;
 
351
               ^
 
352
DETAIL:  Different point dimensions in (1,2,3) and (2,3).
 
353
SELECT '(1,2),(1,2,3)'::cube AS cube; -- 3
 
354
ERROR:  bad cube representation
 
355
LINE 1: SELECT '(1,2),(1,2,3)'::cube AS cube;
 
356
               ^
 
357
DETAIL:  Different point dimensions in (1,2) and (1,2,3).
 
358
SELECT '(1,2,3)ab'::cube AS cube; -- 4
 
359
ERROR:  bad cube representation
 
360
LINE 1: SELECT '(1,2,3)ab'::cube AS cube;
 
361
               ^
 
362
DETAIL:  syntax error at or near "a"
 
363
SELECT '(1,2,3)a'::cube AS cube; -- 5
 
364
ERROR:  bad cube representation
 
365
LINE 1: SELECT '(1,2,3)a'::cube AS cube;
 
366
               ^
 
367
DETAIL:  syntax error at or near "a"
 
368
SELECT '(1,2)('::cube AS cube; -- 5
 
369
ERROR:  bad cube representation
 
370
LINE 1: SELECT '(1,2)('::cube AS cube;
 
371
               ^
 
372
DETAIL:  syntax error at or near "("
 
373
SELECT '1,2ab'::cube AS cube; -- 6
 
374
ERROR:  bad cube representation
 
375
LINE 1: SELECT '1,2ab'::cube AS cube;
 
376
               ^
 
377
DETAIL:  syntax error at or near "a"
 
378
SELECT '1 e7'::cube AS cube; -- 6
 
379
ERROR:  bad cube representation
 
380
LINE 1: SELECT '1 e7'::cube AS cube;
 
381
               ^
 
382
DETAIL:  syntax error at or near "e"
 
383
SELECT '1,2a'::cube AS cube; -- 7
 
384
ERROR:  bad cube representation
 
385
LINE 1: SELECT '1,2a'::cube AS cube;
 
386
               ^
 
387
DETAIL:  syntax error at or near "a"
 
388
SELECT '1..2'::cube AS cube; -- 7
 
389
ERROR:  bad cube representation
 
390
LINE 1: SELECT '1..2'::cube AS cube;
 
391
               ^
 
392
DETAIL:  syntax error at or near ".2"
 
393
--
 
394
-- Testing building cubes from float8 values
 
395
--
 
396
SELECT cube(0::float8);
 
397
 cube 
 
398
------
 
399
 (0)
 
400
(1 row)
 
401
 
 
402
SELECT cube(1::float8);
 
403
 cube 
 
404
------
 
405
 (1)
 
406
(1 row)
 
407
 
 
408
SELECT cube(1,2);
 
409
  cube   
 
410
---------
 
411
 (1),(2)
 
412
(1 row)
 
413
 
 
414
SELECT cube(cube(1,2),3);
 
415
     cube      
 
416
---------------
 
417
 (1, 3),(2, 3)
 
418
(1 row)
 
419
 
 
420
SELECT cube(cube(1,2),3,4);
 
421
     cube      
 
422
---------------
 
423
 (1, 3),(2, 4)
 
424
(1 row)
 
425
 
 
426
SELECT cube(cube(cube(1,2),3,4),5);
 
427
        cube         
 
428
---------------------
 
429
 (1, 3, 5),(2, 4, 5)
 
430
(1 row)
 
431
 
 
432
SELECT cube(cube(cube(1,2),3,4),5,6);
 
433
        cube         
 
434
---------------------
 
435
 (1, 3, 5),(2, 4, 6)
 
436
(1 row)
 
437
 
 
438
--
 
439
-- Test that the text -> cube cast was installed.
 
440
--
 
441
SELECT '(0)'::text::cube;
 
442
 cube 
 
443
------
 
444
 (0)
 
445
(1 row)
 
446
 
 
447
--
 
448
-- Test the float[] -> cube cast
 
449
--
 
450
SELECT cube('{0,1,2}'::float[], '{3,4,5}'::float[]);
 
451
        cube         
 
452
---------------------
 
453
 (0, 1, 2),(3, 4, 5)
 
454
(1 row)
 
455
 
 
456
SELECT cube('{0,1,2}'::float[], '{3}'::float[]);
 
457
ERROR:  UR and LL arrays must be of same length
 
458
SELECT cube(NULL::float[], '{3}'::float[]);
 
459
 cube 
 
460
------
 
461
 
 
462
(1 row)
 
463
 
 
464
SELECT cube('{0,1,2}'::float[]);
 
465
   cube    
 
466
-----------
 
467
 (0, 1, 2)
 
468
(1 row)
 
469
 
 
470
SELECT cube_subset(cube('(1,3,5),(6,7,8)'), ARRAY[3,2,1,1]);
 
471
        cube_subset        
 
472
---------------------------
 
473
 (5, 3, 1, 1),(8, 7, 6, 6)
 
474
(1 row)
 
475
 
 
476
SELECT cube_subset(cube('(1,3,5),(6,7,8)'), ARRAY[4,0]);
 
477
ERROR:  Index out of bounds
 
478
--
 
479
-- Testing limit of CUBE_MAX_DIM dimensions check in cube_in.
 
480
--
 
481
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;
 
482
ERROR:  bad cube representation
 
483
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...
 
484
               ^
 
485
DETAIL:  A cube cannot have more than 100 dimensions.
 
486
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;
 
487
ERROR:  bad cube representation
 
488
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...
 
489
               ^
 
490
DETAIL:  A cube cannot have more than 100 dimensions.
 
491
--
 
492
-- testing the  operators
 
493
--
 
494
-- equality/inequality:
 
495
--
 
496
SELECT '24, 33.20'::cube    =  '24, 33.20'::cube AS bool;
 
497
 bool 
 
498
------
 
499
 t
 
500
(1 row)
 
501
 
 
502
SELECT '24, 33.20'::cube    != '24, 33.20'::cube AS bool;
 
503
 bool 
 
504
------
 
505
 f
 
506
(1 row)
 
507
 
 
508
SELECT '24, 33.20'::cube    =  '24, 33.21'::cube AS bool;
 
509
 bool 
 
510
------
 
511
 f
 
512
(1 row)
 
513
 
 
514
SELECT '24, 33.20'::cube    != '24, 33.21'::cube AS bool;
 
515
 bool 
 
516
------
 
517
 t
 
518
(1 row)
 
519
 
 
520
SELECT '(2,0),(3,1)'::cube  =  '(2,0,0,0,0),(3,1,0,0,0)'::cube AS bool;
 
521
 bool 
 
522
------
 
523
 f
 
524
(1 row)
 
525
 
 
526
SELECT '(2,0),(3,1)'::cube  =  '(2,0,0,0,0),(3,1,0,0,1)'::cube AS bool;
 
527
 bool 
 
528
------
 
529
 f
 
530
(1 row)
 
531
 
 
532
-- "lower than" / "greater than"
 
533
-- (these operators are not useful for anything but ordering)
 
534
--
 
535
SELECT '1'::cube   > '2'::cube AS bool;
 
536
 bool 
 
537
------
 
538
 f
 
539
(1 row)
 
540
 
 
541
SELECT '1'::cube   < '2'::cube AS bool;
 
542
 bool 
 
543
------
 
544
 t
 
545
(1 row)
 
546
 
 
547
SELECT '1,1'::cube > '1,2'::cube AS bool;
 
548
 bool 
 
549
------
 
550
 f
 
551
(1 row)
 
552
 
 
553
SELECT '1,1'::cube < '1,2'::cube AS bool;
 
554
 bool 
 
555
------
 
556
 t
 
557
(1 row)
 
558
 
 
559
SELECT '(2,0),(3,1)'::cube             > '(2,0,0,0,0),(3,1,0,0,1)'::cube AS bool;
 
560
 bool 
 
561
------
 
562
 f
 
563
(1 row)
 
564
 
 
565
SELECT '(2,0),(3,1)'::cube             < '(2,0,0,0,0),(3,1,0,0,1)'::cube AS bool;
 
566
 bool 
 
567
------
 
568
 t
 
569
(1 row)
 
570
 
 
571
SELECT '(2,0),(3,1)'::cube             > '(2,0,0,0,1),(3,1,0,0,0)'::cube AS bool;
 
572
 bool 
 
573
------
 
574
 f
 
575
(1 row)
 
576
 
 
577
SELECT '(2,0),(3,1)'::cube             < '(2,0,0,0,1),(3,1,0,0,0)'::cube AS bool;
 
578
 bool 
 
579
------
 
580
 t
 
581
(1 row)
 
582
 
 
583
SELECT '(2,0),(3,1)'::cube             > '(2,0,0,0,0),(3,1,0,0,0)'::cube AS bool;
 
584
 bool 
 
585
------
 
586
 f
 
587
(1 row)
 
588
 
 
589
SELECT '(2,0),(3,1)'::cube             < '(2,0,0,0,0),(3,1,0,0,0)'::cube AS bool;
 
590
 bool 
 
591
------
 
592
 t
 
593
(1 row)
 
594
 
 
595
SELECT '(2,0,0,0,0),(3,1,0,0,1)'::cube > '(2,0),(3,1)'::cube AS bool;
 
596
 bool 
 
597
------
 
598
 t
 
599
(1 row)
 
600
 
 
601
SELECT '(2,0,0,0,0),(3,1,0,0,1)'::cube < '(2,0),(3,1)'::cube AS bool;
 
602
 bool 
 
603
------
 
604
 f
 
605
(1 row)
 
606
 
 
607
SELECT '(2,0,0,0,1),(3,1,0,0,0)'::cube > '(2,0),(3,1)'::cube AS bool;
 
608
 bool 
 
609
------
 
610
 t
 
611
(1 row)
 
612
 
 
613
SELECT '(2,0,0,0,1),(3,1,0,0,0)'::cube < '(2,0),(3,1)'::cube AS bool;
 
614
 bool 
 
615
------
 
616
 f
 
617
(1 row)
 
618
 
 
619
SELECT '(2,0,0,0,0),(3,1,0,0,0)'::cube > '(2,0),(3,1)'::cube AS bool;
 
620
 bool 
 
621
------
 
622
 t
 
623
(1 row)
 
624
 
 
625
SELECT '(2,0,0,0,0),(3,1,0,0,0)'::cube < '(2,0),(3,1)'::cube AS bool;
 
626
 bool 
 
627
------
 
628
 f
 
629
(1 row)
 
630
 
 
631
-- "overlap"
 
632
--
 
633
SELECT '1'::cube && '1'::cube AS bool;
 
634
 bool 
 
635
------
 
636
 t
 
637
(1 row)
 
638
 
 
639
SELECT '1'::cube && '2'::cube AS bool;
 
640
 bool 
 
641
------
 
642
 f
 
643
(1 row)
 
644
 
 
645
SELECT '[(-1,-1,-1),(1,1,1)]'::cube && '0'::cube AS bool;
 
646
 bool 
 
647
------
 
648
 t
 
649
(1 row)
 
650
 
 
651
SELECT '[(-1,-1,-1),(1,1,1)]'::cube && '1'::cube AS bool;
 
652
 bool 
 
653
------
 
654
 t
 
655
(1 row)
 
656
 
 
657
SELECT '[(-1,-1,-1),(1,1,1)]'::cube && '1,1,1'::cube AS bool;
 
658
 bool 
 
659
------
 
660
 t
 
661
(1 row)
 
662
 
 
663
SELECT '[(-1,-1,-1),(1,1,1)]'::cube && '[(1,1,1),(2,2,2)]'::cube AS bool;
 
664
 bool 
 
665
------
 
666
 t
 
667
(1 row)
 
668
 
 
669
SELECT '[(-1,-1,-1),(1,1,1)]'::cube && '[(1,1),(2,2)]'::cube AS bool;
 
670
 bool 
 
671
------
 
672
 t
 
673
(1 row)
 
674
 
 
675
SELECT '[(-1,-1,-1),(1,1,1)]'::cube && '[(2,1,1),(2,2,2)]'::cube AS bool;
 
676
 bool 
 
677
------
 
678
 f
 
679
(1 row)
 
680
 
 
681
-- "contained in" (the left operand is the cube entirely enclosed by
 
682
-- the right operand):
 
683
--
 
684
SELECT '0'::cube                 <@ '0'::cube                        AS bool;
 
685
 bool 
 
686
------
 
687
 t
 
688
(1 row)
 
689
 
 
690
SELECT '0,0,0'::cube             <@ '0,0,0'::cube                    AS bool;
 
691
 bool 
 
692
------
 
693
 t
 
694
(1 row)
 
695
 
 
696
SELECT '0,0'::cube               <@ '0,0,1'::cube                    AS bool;
 
697
 bool 
 
698
------
 
699
 t
 
700
(1 row)
 
701
 
 
702
SELECT '0,0,0'::cube             <@ '0,0,1'::cube                    AS bool;
 
703
 bool 
 
704
------
 
705
 f
 
706
(1 row)
 
707
 
 
708
SELECT '1,0,0'::cube             <@ '0,0,1'::cube                    AS bool;
 
709
 bool 
 
710
------
 
711
 f
 
712
(1 row)
 
713
 
 
714
SELECT '(1,0,0),(0,0,1)'::cube   <@ '(1,0,0),(0,0,1)'::cube          AS bool;
 
715
 bool 
 
716
------
 
717
 t
 
718
(1 row)
 
719
 
 
720
SELECT '(1,0,0),(0,0,1)'::cube   <@ '(-1,-1,-1),(1,1,1)'::cube       AS bool;
 
721
 bool 
 
722
------
 
723
 t
 
724
(1 row)
 
725
 
 
726
SELECT '(1,0,0),(0,0,1)'::cube   <@ '(-1,-1,-1,-1),(1,1,1,1)'::cube  AS bool;
 
727
 bool 
 
728
------
 
729
 t
 
730
(1 row)
 
731
 
 
732
SELECT '0'::cube                 <@ '(-1),(1)'::cube                 AS bool;
 
733
 bool 
 
734
------
 
735
 t
 
736
(1 row)
 
737
 
 
738
SELECT '1'::cube                 <@ '(-1),(1)'::cube                 AS bool;
 
739
 bool 
 
740
------
 
741
 t
 
742
(1 row)
 
743
 
 
744
SELECT '-1'::cube                <@ '(-1),(1)'::cube                 AS bool;
 
745
 bool 
 
746
------
 
747
 t
 
748
(1 row)
 
749
 
 
750
SELECT '(-1),(1)'::cube          <@ '(-1),(1)'::cube                 AS bool;
 
751
 bool 
 
752
------
 
753
 t
 
754
(1 row)
 
755
 
 
756
SELECT '(-1),(1)'::cube          <@ '(-1,-1),(1,1)'::cube            AS bool;
 
757
 bool 
 
758
------
 
759
 t
 
760
(1 row)
 
761
 
 
762
SELECT '(-2),(1)'::cube          <@ '(-1),(1)'::cube                 AS bool;
 
763
 bool 
 
764
------
 
765
 f
 
766
(1 row)
 
767
 
 
768
SELECT '(-2),(1)'::cube          <@ '(-1,-1),(1,1)'::cube            AS bool;
 
769
 bool 
 
770
------
 
771
 f
 
772
(1 row)
 
773
 
 
774
-- "contains" (the left operand is the cube that entirely encloses the
 
775
-- right operand)
 
776
--
 
777
SELECT '0'::cube                        @> '0'::cube                 AS bool;
 
778
 bool 
 
779
------
 
780
 t
 
781
(1 row)
 
782
 
 
783
SELECT '0,0,0'::cube                    @> '0,0,0'::cube             AS bool;
 
784
 bool 
 
785
------
 
786
 t
 
787
(1 row)
 
788
 
 
789
SELECT '0,0,1'::cube                    @> '0,0'::cube               AS bool;
 
790
 bool 
 
791
------
 
792
 t
 
793
(1 row)
 
794
 
 
795
SELECT '0,0,1'::cube                    @> '0,0,0'::cube             AS bool;
 
796
 bool 
 
797
------
 
798
 f
 
799
(1 row)
 
800
 
 
801
SELECT '0,0,1'::cube                    @> '1,0,0'::cube             AS bool;
 
802
 bool 
 
803
------
 
804
 f
 
805
(1 row)
 
806
 
 
807
SELECT '(1,0,0),(0,0,1)'::cube          @> '(1,0,0),(0,0,1)'::cube   AS bool;
 
808
 bool 
 
809
------
 
810
 t
 
811
(1 row)
 
812
 
 
813
SELECT '(-1,-1,-1),(1,1,1)'::cube       @> '(1,0,0),(0,0,1)'::cube   AS bool;
 
814
 bool 
 
815
------
 
816
 t
 
817
(1 row)
 
818
 
 
819
SELECT '(-1,-1,-1,-1),(1,1,1,1)'::cube  @> '(1,0,0),(0,0,1)'::cube   AS bool;
 
820
 bool 
 
821
------
 
822
 t
 
823
(1 row)
 
824
 
 
825
SELECT '(-1),(1)'::cube                 @> '0'::cube                 AS bool;
 
826
 bool 
 
827
------
 
828
 t
 
829
(1 row)
 
830
 
 
831
SELECT '(-1),(1)'::cube                 @> '1'::cube                 AS bool;
 
832
 bool 
 
833
------
 
834
 t
 
835
(1 row)
 
836
 
 
837
SELECT '(-1),(1)'::cube                 @> '-1'::cube                AS bool;
 
838
 bool 
 
839
------
 
840
 t
 
841
(1 row)
 
842
 
 
843
SELECT '(-1),(1)'::cube                 @> '(-1),(1)'::cube          AS bool;
 
844
 bool 
 
845
------
 
846
 t
 
847
(1 row)
 
848
 
 
849
SELECT '(-1,-1),(1,1)'::cube            @> '(-1),(1)'::cube          AS bool;
 
850
 bool 
 
851
------
 
852
 t
 
853
(1 row)
 
854
 
 
855
SELECT '(-1),(1)'::cube                 @> '(-2),(1)'::cube          AS bool;
 
856
 bool 
 
857
------
 
858
 f
 
859
(1 row)
 
860
 
 
861
SELECT '(-1,-1),(1,1)'::cube            @> '(-2),(1)'::cube          AS bool;
 
862
 bool 
 
863
------
 
864
 f
 
865
(1 row)
 
866
 
 
867
-- Test of distance function
 
868
--
 
869
SELECT cube_distance('(0)'::cube,'(2,2,2,2)'::cube);
 
870
 cube_distance 
 
871
---------------
 
872
             4
 
873
(1 row)
 
874
 
 
875
SELECT cube_distance('(0)'::cube,'(.3,.4)'::cube);
 
876
 cube_distance 
 
877
---------------
 
878
           0.5
 
879
(1 row)
 
880
 
 
881
-- Test of cube function (text to cube)
 
882
--
 
883
SELECT cube('(1,1.2)'::text);
 
884
   cube   
 
885
----------
 
886
 (1, 1.2)
 
887
(1 row)
 
888
 
 
889
SELECT cube(NULL);
 
890
 cube 
 
891
------
 
892
 
 
893
(1 row)
 
894
 
 
895
-- Test of cube_dim function (dimensions stored in cube)
 
896
--
 
897
SELECT cube_dim('(0)'::cube);
 
898
 cube_dim 
 
899
----------
 
900
        1
 
901
(1 row)
 
902
 
 
903
SELECT cube_dim('(0,0)'::cube);
 
904
 cube_dim 
 
905
----------
 
906
        2
 
907
(1 row)
 
908
 
 
909
SELECT cube_dim('(0,0,0)'::cube);
 
910
 cube_dim 
 
911
----------
 
912
        3
 
913
(1 row)
 
914
 
 
915
-- Test of cube_ll_coord function (retrieves LL coodinate values)
 
916
--
 
917
SELECT cube_ll_coord('(-1,1),(2,-2)'::cube, 1);
 
918
 cube_ll_coord 
 
919
---------------
 
920
            -1
 
921
(1 row)
 
922
 
 
923
SELECT cube_ll_coord('(-1,1),(2,-2)'::cube, 2);
 
924
 cube_ll_coord 
 
925
---------------
 
926
            -2
 
927
(1 row)
 
928
 
 
929
SELECT cube_ll_coord('(-1,1),(2,-2)'::cube, 3);
 
930
 cube_ll_coord 
 
931
---------------
 
932
             0
 
933
(1 row)
 
934
 
 
935
-- Test of cube_ur_coord function (retrieves UR coodinate values)
 
936
--
 
937
SELECT cube_ur_coord('(-1,1),(2,-2)'::cube, 1);
 
938
 cube_ur_coord 
 
939
---------------
 
940
             2
 
941
(1 row)
 
942
 
 
943
SELECT cube_ur_coord('(-1,1),(2,-2)'::cube, 2);
 
944
 cube_ur_coord 
 
945
---------------
 
946
             1
 
947
(1 row)
 
948
 
 
949
SELECT cube_ur_coord('(-1,1),(2,-2)'::cube, 3);
 
950
 cube_ur_coord 
 
951
---------------
 
952
             0
 
953
(1 row)
 
954
 
 
955
-- Test of cube_is_point
 
956
--
 
957
SELECT cube_is_point('(0)'::cube);
 
958
 cube_is_point 
 
959
---------------
 
960
 t
 
961
(1 row)
 
962
 
 
963
SELECT cube_is_point('(0,1,2)'::cube);
 
964
 cube_is_point 
 
965
---------------
 
966
 t
 
967
(1 row)
 
968
 
 
969
SELECT cube_is_point('(0,1,2),(0,1,2)'::cube);
 
970
 cube_is_point 
 
971
---------------
 
972
 t
 
973
(1 row)
 
974
 
 
975
SELECT cube_is_point('(0,1,2),(-1,1,2)'::cube);
 
976
 cube_is_point 
 
977
---------------
 
978
 f
 
979
(1 row)
 
980
 
 
981
SELECT cube_is_point('(0,1,2),(0,-1,2)'::cube);
 
982
 cube_is_point 
 
983
---------------
 
984
 f
 
985
(1 row)
 
986
 
 
987
SELECT cube_is_point('(0,1,2),(0,1,-2)'::cube);
 
988
 cube_is_point 
 
989
---------------
 
990
 f
 
991
(1 row)
 
992
 
 
993
-- Test of cube_enlarge (enlarging and shrinking cubes)
 
994
--
 
995
SELECT cube_enlarge('(0)'::cube, 0, 0);
 
996
 cube_enlarge 
 
997
--------------
 
998
 (0)
 
999
(1 row)
 
1000
 
 
1001
SELECT cube_enlarge('(0)'::cube, 0, 1);
 
1002
 cube_enlarge 
 
1003
--------------
 
1004
 (0)
 
1005
(1 row)
 
1006
 
 
1007
SELECT cube_enlarge('(0)'::cube, 0, 2);
 
1008
 cube_enlarge 
 
1009
--------------
 
1010
 (0)
 
1011
(1 row)
 
1012
 
 
1013
SELECT cube_enlarge('(2),(-2)'::cube, 0, 4);
 
1014
 cube_enlarge 
 
1015
--------------
 
1016
 (-2),(2)
 
1017
(1 row)
 
1018
 
 
1019
SELECT cube_enlarge('(0)'::cube, 1, 0);
 
1020
 cube_enlarge 
 
1021
--------------
 
1022
 (-1),(1)
 
1023
(1 row)
 
1024
 
 
1025
SELECT cube_enlarge('(0)'::cube, 1, 1);
 
1026
 cube_enlarge 
 
1027
--------------
 
1028
 (-1),(1)
 
1029
(1 row)
 
1030
 
 
1031
SELECT cube_enlarge('(0)'::cube, 1, 2);
 
1032
  cube_enlarge   
 
1033
-----------------
 
1034
 (-1, -1),(1, 1)
 
1035
(1 row)
 
1036
 
 
1037
SELECT cube_enlarge('(2),(-2)'::cube, 1, 4);
 
1038
         cube_enlarge          
 
1039
-------------------------------
 
1040
 (-3, -1, -1, -1),(3, 1, 1, 1)
 
1041
(1 row)
 
1042
 
 
1043
SELECT cube_enlarge('(0)'::cube, -1, 0);
 
1044
 cube_enlarge 
 
1045
--------------
 
1046
 (0)
 
1047
(1 row)
 
1048
 
 
1049
SELECT cube_enlarge('(0)'::cube, -1, 1);
 
1050
 cube_enlarge 
 
1051
--------------
 
1052
 (0)
 
1053
(1 row)
 
1054
 
 
1055
SELECT cube_enlarge('(0)'::cube, -1, 2);
 
1056
 cube_enlarge 
 
1057
--------------
 
1058
 (0)
 
1059
(1 row)
 
1060
 
 
1061
SELECT cube_enlarge('(2),(-2)'::cube, -1, 4);
 
1062
 cube_enlarge 
 
1063
--------------
 
1064
 (-1),(1)
 
1065
(1 row)
 
1066
 
 
1067
SELECT cube_enlarge('(0,0,0)'::cube, 1, 0);
 
1068
      cube_enlarge      
 
1069
------------------------
 
1070
 (-1, -1, -1),(1, 1, 1)
 
1071
(1 row)
 
1072
 
 
1073
SELECT cube_enlarge('(0,0,0)'::cube, 1, 2);
 
1074
      cube_enlarge      
 
1075
------------------------
 
1076
 (-1, -1, -1),(1, 1, 1)
 
1077
(1 row)
 
1078
 
 
1079
SELECT cube_enlarge('(2,-2),(-3,7)'::cube, 1, 2);
 
1080
  cube_enlarge   
 
1081
-----------------
 
1082
 (-4, -3),(3, 8)
 
1083
(1 row)
 
1084
 
 
1085
SELECT cube_enlarge('(2,-2),(-3,7)'::cube, 3, 2);
 
1086
   cube_enlarge   
 
1087
------------------
 
1088
 (-6, -5),(5, 10)
 
1089
(1 row)
 
1090
 
 
1091
SELECT cube_enlarge('(2,-2),(-3,7)'::cube, -1, 2);
 
1092
  cube_enlarge   
 
1093
-----------------
 
1094
 (-2, -1),(1, 6)
 
1095
(1 row)
 
1096
 
 
1097
SELECT cube_enlarge('(2,-2),(-3,7)'::cube, -3, 2);
 
1098
    cube_enlarge     
 
1099
---------------------
 
1100
 (-0.5, 1),(-0.5, 4)
 
1101
(1 row)
 
1102
 
 
1103
-- Load some example data and build the index
 
1104
--
 
1105
CREATE TABLE test_cube (c cube);
 
1106
\copy test_cube from 'data/test_cube.data'
 
1107
CREATE INDEX test_cube_ix ON test_cube USING gist (c);
 
1108
SELECT * FROM test_cube WHERE c && '(3000,1000),(0,0)' ORDER BY c;
 
1109
            c             
 
1110
--------------------------
 
1111
 (337, 455),(240, 359)
 
1112
 (759, 187),(662, 163)
 
1113
 (1444, 403),(1346, 344)
 
1114
 (1594, 1043),(1517, 971)
 
1115
 (2424, 160),(2424, 81)
 
1116
(5 rows)
 
1117
 
 
1118
-- Test sorting
 
1119
SELECT * FROM test_cube WHERE c && '(3000,1000),(0,0)' GROUP BY c ORDER BY c;
 
1120
            c             
 
1121
--------------------------
 
1122
 (337, 455),(240, 359)
 
1123
 (759, 187),(662, 163)
 
1124
 (1444, 403),(1346, 344)
 
1125
 (1594, 1043),(1517, 971)
 
1126
 (2424, 160),(2424, 81)
 
1127
(5 rows)
 
1128