1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>9.20. Range/Multirange Functions and Operators</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="functions-array.html" title="9.19. Array Functions and Operators" /><link rel="next" href="functions-aggregate.html" title="9.21. Aggregate Functions" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">9.20. Range/Multirange Functions and Operators</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="functions-array.html" title="9.19. Array Functions and Operators">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="functions.html" title="Chapter 9. Functions and Operators">Up</a></td><th width="60%" align="center">Chapter 9. Functions and Operators</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 15.7 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="functions-aggregate.html" title="9.21. Aggregate Functions">Next</a></td></tr></table><hr /></div><div class="sect1" id="FUNCTIONS-RANGE"><div class="titlepage"><div><div><h2 class="title" style="clear: both">9.20. Range/Multirange Functions and Operators</h2></div></div></div><p>
See <a class="xref" href="rangetypes.html" title="8.17. Range Types">Section 8.17</a> for an overview of range types.
</p><p>
<a class="xref" href="functions-range.html#RANGE-OPERATORS-TABLE" title="Table 9.54. Range Operators">Table 9.54</a> shows the specialized operators
available for range types.
<a class="xref" href="functions-range.html#MULTIRANGE-OPERATORS-TABLE" title="Table 9.55. Multirange Operators">Table 9.55</a> shows the specialized operators
available for multirange types.
In addition to those, the usual comparison operators shown in
<a class="xref" href="functions-comparison.html#FUNCTIONS-COMPARISON-OP-TABLE" title="Table 9.1. Comparison Operators">Table 9.1</a> are available for range
and multirange types. The comparison operators order first by the range lower
bounds, and only if those are equal do they compare the upper bounds. The
multirange operators compare each range until one is unequal. This
does not usually result in a useful overall ordering, but the operators are
provided to allow unique indexes to be constructed on ranges.
</p><div class="table" id="RANGE-OPERATORS-TABLE"><p class="title"><strong>Table 9.54. Range Operators</strong></p><div class="table-contents"><table class="table" summary="Range Operators" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
Operator
</p>
<p>
Description
</p>
<p>
Example(s)
</p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal">@></code> <code class="type">anyrange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Does the first range contain the second?
</p>
<p>
<code class="literal">int4range(2,4) @> int4range(2,3)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal">@></code> <code class="type">anyelement</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Does the range contain the element?
</p>
<p>
<code class="literal">'[2011-01-01,2011-03-01)'::tsrange @> '2011-01-10'::timestamp</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal"><@</code> <code class="type">anyrange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the first range contained by the second?
</p>
<p>
<code class="literal">int4range(2,4) <@ int4range(1,7)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyelement</code> <code class="literal"><@</code> <code class="type">anyrange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the element contained in the range?
</p>
<p>
<code class="literal">42 <@ int4range(1,7)</code>
→ <code class="returnvalue">f</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal">&&</code> <code class="type">anyrange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Do the ranges overlap, that is, have any elements in common?
</p>
<p>
<code class="literal">int8range(3,7) && int8range(4,12)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal"><<</code> <code class="type">anyrange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the first range strictly left of the second?
</p>
<p>
<code class="literal">int8range(1,10) << int8range(100,110)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal">>></code> <code class="type">anyrange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the first range strictly right of the second?
</p>
<p>
<code class="literal">int8range(50,60) >> int8range(20,30)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal">&<</code> <code class="type">anyrange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Does the first range not extend to the right of the second?
</p>
<p>
<code class="literal">int8range(1,20) &< int8range(18,20)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal">&></code> <code class="type">anyrange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Does the first range not extend to the left of the second?
</p>
<p>
<code class="literal">int8range(7,20) &> int8range(5,10)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal">-|-</code> <code class="type">anyrange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Are the ranges adjacent?
</p>
<p>
<code class="literal">numrange(1.1,2.2) -|- numrange(2.2,3.3)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal">+</code> <code class="type">anyrange</code>
→ <code class="returnvalue">anyrange</code>
</p>
<p>
Computes the union of the ranges. The ranges must overlap or be
adjacent, so that the union is a single range (but
see <code class="function">range_merge()</code>).
</p>
<p>
<code class="literal">numrange(5,15) + numrange(10,20)</code>
→ <code class="returnvalue">[5,20)</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal">*</code> <code class="type">anyrange</code>
→ <code class="returnvalue">anyrange</code>
</p>
<p>
Computes the intersection of the ranges.
</p>
<p>
<code class="literal">int8range(5,15) * int8range(10,20)</code>
→ <code class="returnvalue">[10,15)</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal">-</code> <code class="type">anyrange</code>
→ <code class="returnvalue">anyrange</code>
</p>
<p>
Computes the difference of the ranges. The second range must not be
contained in the first in such a way that the difference would not be
a single range.
</p>
<p>
<code class="literal">int8range(5,15) - int8range(10,20)</code>
→ <code class="returnvalue">[5,10)</code>
</p></td></tr></tbody></table></div></div><br class="table-break" /><div class="table" id="MULTIRANGE-OPERATORS-TABLE"><p class="title"><strong>Table 9.55. Multirange Operators</strong></p><div class="table-contents"><table class="table" summary="Multirange Operators" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
Operator
</p>
<p>
Description
</p>
<p>
Example(s)
</p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal">@></code> <code class="type">anymultirange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Does the first multirange contain the second?
</p>
<p>
<code class="literal">'{[2,4)}'::int4multirange @> '{[2,3)}'::int4multirange</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal">@></code> <code class="type">anyrange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Does the multirange contain the range?
</p>
<p>
<code class="literal">'{[2,4)}'::int4multirange @> int4range(2,3)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal">@></code> <code class="type">anyelement</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Does the multirange contain the element?
</p>
<p>
<code class="literal">'{[2011-01-01,2011-03-01)}'::tsmultirange @> '2011-01-10'::timestamp</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal">@></code> <code class="type">anymultirange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Does the range contain the multirange?
</p>
<p>
<code class="literal">'[2,4)'::int4range @> '{[2,3)}'::int4multirange</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal"><@</code> <code class="type">anymultirange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the first multirange contained by the second?
</p>
<p>
<code class="literal">'{[2,4)}'::int4multirange <@ '{[1,7)}'::int4multirange</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal"><@</code> <code class="type">anyrange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the multirange contained by the range?
</p>
<p>
<code class="literal">'{[2,4)}'::int4multirange <@ int4range(1,7)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal"><@</code> <code class="type">anymultirange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the range contained by the multirange?
</p>
<p>
<code class="literal">int4range(2,4) <@ '{[1,7)}'::int4multirange</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyelement</code> <code class="literal"><@</code> <code class="type">anymultirange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the element contained by the multirange?
</p>
<p>
<code class="literal">4 <@ '{[1,7)}'::int4multirange</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal">&&</code> <code class="type">anymultirange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Do the multiranges overlap, that is, have any elements in common?
</p>
<p>
<code class="literal">'{[3,7)}'::int8multirange && '{[4,12)}'::int8multirange</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal">&&</code> <code class="type">anyrange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Does the multirange overlap the range?
</p>
<p>
<code class="literal">'{[3,7)}'::int8multirange && int8range(4,12)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal">&&</code> <code class="type">anymultirange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Does the range overlap the multirange?
</p>
<p>
<code class="literal">int8range(3,7) && '{[4,12)}'::int8multirange</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal"><<</code> <code class="type">anymultirange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the first multirange strictly left of the second?
</p>
<p>
<code class="literal">'{[1,10)}'::int8multirange << '{[100,110)}'::int8multirange</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal"><<</code> <code class="type">anyrange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the multirange strictly left of the range?
</p>
<p>
<code class="literal">'{[1,10)}'::int8multirange << int8range(100,110)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal"><<</code> <code class="type">anymultirange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the range strictly left of the multirange?
</p>
<p>
<code class="literal">int8range(1,10) << '{[100,110)}'::int8multirange</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal">>></code> <code class="type">anymultirange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the first multirange strictly right of the second?
</p>
<p>
<code class="literal">'{[50,60)}'::int8multirange >> '{[20,30)}'::int8multirange</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal">>></code> <code class="type">anyrange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the multirange strictly right of the range?
</p>
<p>
<code class="literal">'{[50,60)}'::int8multirange >> int8range(20,30)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal">>></code> <code class="type">anymultirange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the range strictly right of the multirange?
</p>
<p>
<code class="literal">int8range(50,60) >> '{[20,30)}'::int8multirange</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal">&<</code> <code class="type">anymultirange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Does the first multirange not extend to the right of the second?
</p>
<p>
<code class="literal">'{[1,20)}'::int8multirange &< '{[18,20)}'::int8multirange</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal">&<</code> <code class="type">anyrange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Does the multirange not extend to the right of the range?
</p>
<p>
<code class="literal">'{[1,20)}'::int8multirange &< int8range(18,20)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal">&<</code> <code class="type">anymultirange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Does the range not extend to the right of the multirange?
</p>
<p>
<code class="literal">int8range(1,20) &< '{[18,20)}'::int8multirange</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal">&></code> <code class="type">anymultirange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Does the first multirange not extend to the left of the second?
</p>
<p>
<code class="literal">'{[7,20)}'::int8multirange &> '{[5,10)}'::int8multirange</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal">&></code> <code class="type">anyrange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Does the multirange not extend to the left of the range?
</p>
<p>
<code class="literal">'{[7,20)}'::int8multirange &> int8range(5,10)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal">&></code> <code class="type">anymultirange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Does the range not extend to the left of the multirange?
</p>
<p>
<code class="literal">int8range(7,20) &> '{[5,10)}'::int8multirange</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal">-|-</code> <code class="type">anymultirange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Are the multiranges adjacent?
</p>
<p>
<code class="literal">'{[1.1,2.2)}'::nummultirange -|- '{[2.2,3.3)}'::nummultirange</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal">-|-</code> <code class="type">anyrange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the multirange adjacent to the range?
</p>
<p>
<code class="literal">'{[1.1,2.2)}'::nummultirange -|- numrange(2.2,3.3)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anyrange</code> <code class="literal">-|-</code> <code class="type">anymultirange</code>
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the range adjacent to the multirange?
</p>
<p>
<code class="literal">numrange(1.1,2.2) -|- '{[2.2,3.3)}'::nummultirange</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal">+</code> <code class="type">anymultirange</code>
→ <code class="returnvalue">anymultirange</code>
</p>
<p>
Computes the union of the multiranges. The multiranges need not overlap
or be adjacent.
</p>
<p>
<code class="literal">'{[5,10)}'::nummultirange + '{[15,20)}'::nummultirange</code>
→ <code class="returnvalue">{[5,10), [15,20)}</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal">*</code> <code class="type">anymultirange</code>
→ <code class="returnvalue">anymultirange</code>
</p>
<p>
Computes the intersection of the multiranges.
</p>
<p>
<code class="literal">'{[5,15)}'::int8multirange * '{[10,20)}'::int8multirange</code>
→ <code class="returnvalue">{[10,15)}</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<code class="type">anymultirange</code> <code class="literal">-</code> <code class="type">anymultirange</code>
→ <code class="returnvalue">anymultirange</code>
</p>
<p>
Computes the difference of the multiranges.
</p>
<p>
<code class="literal">'{[5,20)}'::int8multirange - '{[10,15)}'::int8multirange</code>
→ <code class="returnvalue">{[5,10), [15,20)}</code>
</p></td></tr></tbody></table></div></div><br class="table-break" /><p>
The left-of/right-of/adjacent operators always return false when an empty
range or multirange is involved; that is, an empty range is not considered to
be either before or after any other range.
</p><p>
Elsewhere empty ranges and multiranges are treated as the additive identity:
anything unioned with an empty value is itself. Anything minus an empty
value is itself. An empty multirange has exactly the same points as an empty
range. Every range contains the empty range. Every multirange contains as many
empty ranges as you like.
</p><p>
The range union and difference operators will fail if the resulting range would
need to contain two disjoint sub-ranges, as such a range cannot be
represented. There are separate operators for union and difference that take
multirange parameters and return a multirange, and they do not fail even if
their arguments are disjoint. So if you need a union or difference operation
for ranges that may be disjoint, you can avoid errors by first casting your
ranges to multiranges.
</p><p>
<a class="xref" href="functions-range.html#RANGE-FUNCTIONS-TABLE" title="Table 9.56. Range Functions">Table 9.56</a> shows the functions
available for use with range types.
<a class="xref" href="functions-range.html#MULTIRANGE-FUNCTIONS-TABLE" title="Table 9.57. Multirange Functions">Table 9.57</a> shows the functions
available for use with multirange types.
</p><div class="table" id="RANGE-FUNCTIONS-TABLE"><p class="title"><strong>Table 9.56. Range Functions</strong></p><div class="table-contents"><table class="table" summary="Range Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
Function
</p>
<p>
Description
</p>
<p>
Example(s)
</p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
<a id="id-1.5.8.26.10.2.2.1.1.1.1" class="indexterm"></a>
<code class="function">lower</code> ( <code class="type">anyrange</code> )
→ <code class="returnvalue">anyelement</code>
</p>
<p>
Extracts the lower bound of the range (<code class="literal">NULL</code> if the
range is empty or the lower bound is infinite).
</p>
<p>
<code class="literal">lower(numrange(1.1,2.2))</code>
→ <code class="returnvalue">1.1</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<a id="id-1.5.8.26.10.2.2.2.1.1.1" class="indexterm"></a>
<code class="function">upper</code> ( <code class="type">anyrange</code> )
→ <code class="returnvalue">anyelement</code>
</p>
<p>
Extracts the upper bound of the range (<code class="literal">NULL</code> if the
range is empty or the upper bound is infinite).
</p>
<p>
<code class="literal">upper(numrange(1.1,2.2))</code>
→ <code class="returnvalue">2.2</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<a id="id-1.5.8.26.10.2.2.3.1.1.1" class="indexterm"></a>
<code class="function">isempty</code> ( <code class="type">anyrange</code> )
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the range empty?
</p>
<p>
<code class="literal">isempty(numrange(1.1,2.2))</code>
→ <code class="returnvalue">f</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<a id="id-1.5.8.26.10.2.2.4.1.1.1" class="indexterm"></a>
<code class="function">lower_inc</code> ( <code class="type">anyrange</code> )
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the range's lower bound inclusive?
</p>
<p>
<code class="literal">lower_inc(numrange(1.1,2.2))</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<a id="id-1.5.8.26.10.2.2.5.1.1.1" class="indexterm"></a>
<code class="function">upper_inc</code> ( <code class="type">anyrange</code> )
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the range's upper bound inclusive?
</p>
<p>
<code class="literal">upper_inc(numrange(1.1,2.2))</code>
→ <code class="returnvalue">f</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<a id="id-1.5.8.26.10.2.2.6.1.1.1" class="indexterm"></a>
<code class="function">lower_inf</code> ( <code class="type">anyrange</code> )
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the range's lower bound infinite?
</p>
<p>
<code class="literal">lower_inf('(,)'::daterange)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<a id="id-1.5.8.26.10.2.2.7.1.1.1" class="indexterm"></a>
<code class="function">upper_inf</code> ( <code class="type">anyrange</code> )
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the range's upper bound infinite?
</p>
<p>
<code class="literal">upper_inf('(,)'::daterange)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<a id="id-1.5.8.26.10.2.2.8.1.1.1" class="indexterm"></a>
<code class="function">range_merge</code> ( <code class="type">anyrange</code>, <code class="type">anyrange</code> )
→ <code class="returnvalue">anyrange</code>
</p>
<p>
Computes the smallest range that includes both of the given ranges.
</p>
<p>
<code class="literal">range_merge('[1,2)'::int4range, '[3,4)'::int4range)</code>
→ <code class="returnvalue">[1,4)</code>
</p></td></tr></tbody></table></div></div><br class="table-break" /><div class="table" id="MULTIRANGE-FUNCTIONS-TABLE"><p class="title"><strong>Table 9.57. Multirange Functions</strong></p><div class="table-contents"><table class="table" summary="Multirange Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
Function
</p>
<p>
Description
</p>
<p>
Example(s)
</p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
<a id="id-1.5.8.26.11.2.2.1.1.1.1" class="indexterm"></a>
<code class="function">lower</code> ( <code class="type">anymultirange</code> )
→ <code class="returnvalue">anyelement</code>
</p>
<p>
Extracts the lower bound of the multirange (<code class="literal">NULL</code> if the
multirange is empty or the lower bound is infinite).
</p>
<p>
<code class="literal">lower('{[1.1,2.2)}'::nummultirange)</code>
→ <code class="returnvalue">1.1</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<a id="id-1.5.8.26.11.2.2.2.1.1.1" class="indexterm"></a>
<code class="function">upper</code> ( <code class="type">anymultirange</code> )
→ <code class="returnvalue">anyelement</code>
</p>
<p>
Extracts the upper bound of the multirange (<code class="literal">NULL</code> if the
multirange is empty or the upper bound is infinite).
</p>
<p>
<code class="literal">upper('{[1.1,2.2)}'::nummultirange)</code>
→ <code class="returnvalue">2.2</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<a id="id-1.5.8.26.11.2.2.3.1.1.1" class="indexterm"></a>
<code class="function">isempty</code> ( <code class="type">anymultirange</code> )
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the multirange empty?
</p>
<p>
<code class="literal">isempty('{[1.1,2.2)}'::nummultirange)</code>
→ <code class="returnvalue">f</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<a id="id-1.5.8.26.11.2.2.4.1.1.1" class="indexterm"></a>
<code class="function">lower_inc</code> ( <code class="type">anymultirange</code> )
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the multirange's lower bound inclusive?
</p>
<p>
<code class="literal">lower_inc('{[1.1,2.2)}'::nummultirange)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<a id="id-1.5.8.26.11.2.2.5.1.1.1" class="indexterm"></a>
<code class="function">upper_inc</code> ( <code class="type">anymultirange</code> )
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the multirange's upper bound inclusive?
</p>
<p>
<code class="literal">upper_inc('{[1.1,2.2)}'::nummultirange)</code>
→ <code class="returnvalue">f</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<a id="id-1.5.8.26.11.2.2.6.1.1.1" class="indexterm"></a>
<code class="function">lower_inf</code> ( <code class="type">anymultirange</code> )
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the multirange's lower bound infinite?
</p>
<p>
<code class="literal">lower_inf('{(,)}'::datemultirange)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<a id="id-1.5.8.26.11.2.2.7.1.1.1" class="indexterm"></a>
<code class="function">upper_inf</code> ( <code class="type">anymultirange</code> )
→ <code class="returnvalue">boolean</code>
</p>
<p>
Is the multirange's upper bound infinite?
</p>
<p>
<code class="literal">upper_inf('{(,)}'::datemultirange)</code>
→ <code class="returnvalue">t</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<a id="id-1.5.8.26.11.2.2.8.1.1.1" class="indexterm"></a>
<code class="function">range_merge</code> ( <code class="type">anymultirange</code> )
→ <code class="returnvalue">anyrange</code>
</p>
<p>
Computes the smallest range that includes the entire multirange.
</p>
<p>
<code class="literal">range_merge('{[1,2), [3,4)}'::int4multirange)</code>
→ <code class="returnvalue">[1,4)</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<a id="id-1.5.8.26.11.2.2.9.1.1.1" class="indexterm"></a>
<code class="function">multirange</code> ( <code class="type">anyrange</code> )
→ <code class="returnvalue">anymultirange</code>
</p>
<p>
Returns a multirange containing just the given range.
</p>
<p>
<code class="literal">multirange('[1,2)'::int4range)</code>
→ <code class="returnvalue">{[1,2)}</code>
</p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
<a id="id-1.5.8.26.11.2.2.10.1.1.1" class="indexterm"></a>
<code class="function">unnest</code> ( <code class="type">anymultirange</code> )
→ <code class="returnvalue">setof anyrange</code>
</p>
<p>
Expands a multirange into a set of ranges.
The ranges are read out in storage order (ascending).
</p>
<p>
<code class="literal">unnest('{[1,2), [3,4)}'::int4multirange)</code>
→ <code class="returnvalue"></code>
</p><pre class="programlisting">
[1,2)
[3,4)
</pre><p>
</p></td></tr></tbody></table></div></div><br class="table-break" /><p>
The <code class="function">lower_inc</code>, <code class="function">upper_inc</code>,
<code class="function">lower_inf</code>, and <code class="function">upper_inf</code>
functions all return false for an empty range or multirange.
</p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="functions-array.html" title="9.19. Array Functions and Operators">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="functions.html" title="Chapter 9. Functions and Operators">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="functions-aggregate.html" title="9.21. Aggregate Functions">Next</a></td></tr><tr><td width="40%" align="left" valign="top">9.19. Array Functions and Operators </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 15.7 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 9.21. Aggregate Functions</td></tr></table></div></body></html>
|