35
35
<itemizedlist>
36
36
<listitem>
37
37
<para>
38
- <type>INT4RANGE </type> — Range of <type>INTEGER </type>
38
+ <type>int4range </type> — Range of <type>integer </type>
39
39
</para>
40
40
</listitem>
41
41
<listitem>
42
42
<para>
43
- <type>INT8RANGE </type> — Range of <type>BIGINT </type>
43
+ <type>int8range </type> — Range of <type>bigint </type>
44
44
</para>
45
45
</listitem>
46
46
<listitem>
47
47
<para>
48
- <type>NUMRANGE </type> — Range of <type>NUMERIC </type>
48
+ <type>numrange </type> — Range of <type>numeric </type>
49
49
</para>
50
50
</listitem>
51
51
<listitem>
52
52
<para>
53
- <type>TSRANGE </type> — Range of <type>TIMESTAMP WITHOUT TIME ZONE </type>
53
+ <type>tsrange </type> — Range of <type>timestamp without time zone </type>
54
54
</para>
55
55
</listitem>
56
56
<listitem>
57
57
<para>
58
- <type>TSTZRANGE </type> — Range of <type>TIMESTAMP WITH TIME ZONE </type>
58
+ <type>tstzrange </type> — Range of <type>timestamp with time zone </type>
59
59
</para>
60
60
</listitem>
61
61
<listitem>
62
62
<para>
63
- <type>DATERANGE </type> — Range of <type>DATE </type>
63
+ <type>daterange </type> — Range of <type>date </type>
64
64
</para>
65
65
</listitem>
66
66
</itemizedlist>
74
74
75
75
<para>
76
76
<programlisting>
77
- CREATE TABLE reservation ( room int, during TSRANGE );
77
+ CREATE TABLE reservation (room int, during tsrange );
78
78
INSERT INTO reservation VALUES
79
- ( 1108, '[2010-01-01 14:30, 2010-01-01 15:30)' );
79
+ ( 1108, '[2010-01-01 14:30, 2010-01-01 15:30)');
80
80
81
81
-- Containment
82
82
SELECT int4range(10, 20) @> 3;
@@ -223,16 +223,16 @@ empty
223
223
Examples:
224
224
<programlisting>
225
225
-- includes 3, does not include 7, and does include all points in between
226
- select '[3,7)'::int4range;
226
+ SELECT '[3,7)'::int4range;
227
227
228
228
-- does not include either 3 or 7, but includes all points in between
229
- select '(3,7)'::int4range;
229
+ SELECT '(3,7)'::int4range;
230
230
231
231
-- includes only the single point 4
232
- select '[4,4]'::int4range;
232
+ SELECT '[4,4]'::int4range;
233
233
234
234
-- includes no points (and will be normalized to 'empty')
235
- select '[4,4)'::int4range;
235
+ SELECT '[4,4)'::int4range;
236
236
</programlisting>
237
237
</para>
238
238
</sect2>
@@ -279,13 +279,13 @@ SELECT numrange(NULL, 2.2);
279
279
280
280
<para>
281
281
A discrete range is one whose element type has a well-defined
282
- <quote>step</quote>, such as <type>INTEGER </type> or <type>DATE </type>.
282
+ <quote>step</quote>, such as <type>integer </type> or <type>date </type>.
283
283
In these types two elements can be said to be adjacent, when there are
284
284
no valid values between them. This contrasts with continuous ranges,
285
285
where it's always (or almost always) possible to identify other element
286
286
values between two given values. For example, a range over the
287
- <type>NUMERIC </> type is continuous, as is a range over <type>TIMESTAMP </>.
288
- (Even though <type>TIMESTAMP </> has limited precision, and so could
287
+ <type>numeric </> type is continuous, as is a range over <type>timestamp </>.
288
+ (Even though <type>timestamp </> has limited precision, and so could
289
289
theoretically be treated as discrete, it's better to consider it continuous
290
290
since the step size is normally not of interest.)
291
291
</para>
@@ -313,8 +313,8 @@ SELECT numrange(NULL, 2.2);
313
313
</para>
314
314
315
315
<para>
316
- The built-in range types <type>INT4RANGE </type>, <type>INT8RANGE </type>,
317
- and <type>DATERANGE </type> all use a canonical form that includes
316
+ The built-in range types <type>int4range </type>, <type>int8range </type>,
317
+ and <type>daterange </type> all use a canonical form that includes
318
318
the lower bound and excludes the upper bound; that is,
319
319
<literal>[)</literal>. User-defined range types can use other conventions,
320
320
however.
@@ -332,8 +332,8 @@ SELECT numrange(NULL, 2.2);
332
332
333
333
<programlisting>
334
334
CREATE TYPE floatrange AS RANGE (
335
- subtype = float8,
336
- subtype_diff = float8mi
335
+ subtype = float8,
336
+ subtype_diff = float8mi
337
337
);
338
338
339
339
SELECT '[1.234, 5.678]'::floatrange;
@@ -451,20 +451,19 @@ CREATE INDEX reservation_idx ON reservation USING gist (during);
451
451
range type. For example:
452
452
453
453
<programlisting>
454
- ALTER TABLE reservation
455
- ADD EXCLUDE USING gist (during WITH &&);
454
+ ALTER TABLE reservation ADD EXCLUDE USING gist (during WITH &&);
456
455
</programlisting>
457
456
458
457
That constraint will prevent any overlapping values from existing
459
458
in the table at the same time:
460
459
461
460
<programlisting>
462
461
INSERT INTO reservation VALUES
463
- ( 1108, '[2010-01-01 11:30, 2010-01-01 13:00)' );
462
+ ( 1108, '[2010-01-01 11:30, 2010-01-01 13:00)');
464
463
INSERT 0 1
465
464
466
465
INSERT INTO reservation VALUES
467
- ( 1108, '[2010-01-01 14:45, 2010-01-01 15:45)' );
466
+ ( 1108, '[2010-01-01 14:45, 2010-01-01 15:45)');
468
467
ERROR: conflicting key value violates exclusion constraint "reservation_during_excl"
469
468
DETAIL: Key (during)=([ 2010-01-01 14:45:00, 2010-01-01 15:45:00 )) conflicts
470
469
with existing key (during)=([ 2010-01-01 14:30:00, 2010-01-01 15:30:00 )).
@@ -480,25 +479,24 @@ with existing key (during)=([ 2010-01-01 14:30:00, 2010-01-01 15:30:00 )).
480
479
are equal:
481
480
482
481
<programlisting>
483
- CREATE TABLE room_reservation
484
- (
485
- room TEXT,
486
- during TSRANGE,
487
- EXCLUDE USING gist (room WITH =, during WITH &&)
482
+ CREATE TABLE room_reservation (
483
+ room text,
484
+ during tsrange,
485
+ EXCLUDE USING gist (room WITH =, during WITH &&)
488
486
);
489
487
490
488
INSERT INTO room_reservation VALUES
491
- ( '123A', '[2010-01-01 14:00, 2010-01-01 15:00)' );
489
+ ( '123A', '[2010-01-01 14:00, 2010-01-01 15:00)');
492
490
INSERT 0 1
493
491
494
492
INSERT INTO room_reservation VALUES
495
- ( '123A', '[2010-01-01 14:30, 2010-01-01 15:30)' );
493
+ ( '123A', '[2010-01-01 14:30, 2010-01-01 15:30)');
496
494
ERROR: conflicting key value violates exclusion constraint "room_reservation_room_during_excl"
497
495
DETAIL: Key (room, during)=(123A, [ 2010-01-01 14:30:00, 2010-01-01 15:30:00 )) conflicts with
498
496
existing key (room, during)=(123A, [ 2010-01-01 14:00:00, 2010-01-01 15:00:00 )).
499
497
500
498
INSERT INTO room_reservation VALUES
501
- ( '123B', '[2010-01-01 14:30, 2010-01-01 15:30)' );
499
+ ( '123B', '[2010-01-01 14:30, 2010-01-01 15:30)');
502
500
INSERT 0 1
503
501
</programlisting>
504
502
</para>
0 commit comments