Improve Range Types and Exclusion Constraints example.
Make the examples self-contained to avoid confusion. Per bug report 8367 from KOIZUMI Satoru.
This commit is contained in:
parent
f5c2f5a8f6
commit
be6fcb671e
|
@ -451,7 +451,10 @@ CREATE INDEX reservation_idx ON reservation USING gist (during);
|
||||||
range type. For example:
|
range type. For example:
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
ALTER TABLE reservation ADD EXCLUDE USING gist (during WITH &&);
|
CREATE TABLE reservation (
|
||||||
|
during tsrange,
|
||||||
|
EXCLUDE USING gist (during WITH &&)
|
||||||
|
);
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|
||||||
That constraint will prevent any overlapping values from existing
|
That constraint will prevent any overlapping values from existing
|
||||||
|
@ -459,14 +462,14 @@ ALTER TABLE reservation ADD EXCLUDE USING gist (during WITH &&);
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
INSERT INTO reservation VALUES
|
INSERT INTO reservation VALUES
|
||||||
(1108, '[2010-01-01 11:30, 2010-01-01 13:00)');
|
('[2010-01-01 11:30, 2010-01-01 15:00)');
|
||||||
INSERT 0 1
|
INSERT 0 1
|
||||||
|
|
||||||
INSERT INTO reservation VALUES
|
INSERT INTO reservation VALUES
|
||||||
(1108, '[2010-01-01 14:45, 2010-01-01 15:45)');
|
('[2010-01-01 14:45, 2010-01-01 15:45)');
|
||||||
ERROR: conflicting key value violates exclusion constraint "reservation_during_excl"
|
ERROR: conflicting key value violates exclusion constraint "reservation_during_excl"
|
||||||
DETAIL: Key (during)=([ 2010-01-01 14:45:00, 2010-01-01 15:45:00 )) conflicts
|
DETAIL: Key (during)=(["2010-01-01 14:45:00","2010-01-01 15:45:00")) conflicts
|
||||||
with existing key (during)=([ 2010-01-01 14:30:00, 2010-01-01 15:30:00 )).
|
with existing key (during)=(["2010-01-01 11:30:00","2010-01-01 15:00:00")).
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
@ -479,6 +482,7 @@ with existing key (during)=([ 2010-01-01 14:30:00, 2010-01-01 15:30:00 )).
|
||||||
are equal:
|
are equal:
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
CREATE EXTENSION btree_gist;
|
||||||
CREATE TABLE room_reservation (
|
CREATE TABLE room_reservation (
|
||||||
room text,
|
room text,
|
||||||
during tsrange,
|
during tsrange,
|
||||||
|
@ -492,8 +496,8 @@ INSERT 0 1
|
||||||
INSERT INTO room_reservation VALUES
|
INSERT INTO room_reservation VALUES
|
||||||
('123A', '[2010-01-01 14:30, 2010-01-01 15:30)');
|
('123A', '[2010-01-01 14:30, 2010-01-01 15:30)');
|
||||||
ERROR: conflicting key value violates exclusion constraint "room_reservation_room_during_excl"
|
ERROR: conflicting key value violates exclusion constraint "room_reservation_room_during_excl"
|
||||||
DETAIL: Key (room, during)=(123A, [ 2010-01-01 14:30:00, 2010-01-01 15:30:00 )) conflicts with
|
DETAIL: Key (room, during)=(123A, ["2010-01-01 14:30:00","2010-01-01 15:30:00")) conflicts
|
||||||
existing key (room, during)=(123A, [ 2010-01-01 14:00:00, 2010-01-01 15:00:00 )).
|
with existing key (room, during)=(123A, ["2010-01-01 14:00:00","2010-01-01 15:00:00")).
|
||||||
|
|
||||||
INSERT INTO room_reservation VALUES
|
INSERT INTO room_reservation VALUES
|
||||||
('123B', '[2010-01-01 14:30, 2010-01-01 15:30)');
|
('123B', '[2010-01-01 14:30, 2010-01-01 15:30)');
|
||||||
|
|
Loading…
Reference in New Issue