1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-08 06:02:22 +03:00

Rename contrib contains/contained-by operators to @> and <@, per discussion.

This commit is contained in:
Tom Lane
2006-09-10 17:36:52 +00:00
parent ba920e1c91
commit 684ad6a92f
36 changed files with 1290 additions and 1111 deletions

View File

@@ -257,16 +257,22 @@ The operators supported by the GiST access method include:
The segments [a, b] and [c, d] overlap.
[a, b] @ [c, d] Contains
[a, b] @> [c, d] Contains
The segment [a, b] contains the segment [c, d], that is,
a <= c and b >= d
[a, b] @ [c, d] Contained in
[a, b] <@ [c, d] Contained in
The segment [a, b] is contained in [c, d], that is,
a >= c and b <= d
(Before PostgreSQL 8.2, the containment operators @> and <@ were
respectively called @ and ~. These names are still available, but are
deprecated and will eventually be retired. Notice that the old names
are reversed from the convention formerly followed by the core geometric
datatypes!)
Although the mnemonics of the following operators is questionable, I
preserved them to maintain visual consistency with other geometric
data types defined in Postgres.

View File

@@ -5,10 +5,9 @@
-- first, define the datatype. Turn off echoing so that expected file
-- does not depend on contents of seg.sql.
--
SET client_min_messages = warning;
\set ECHO none
psql:seg.sql:10: NOTICE: type "seg" is not yet defined
DETAIL: Creating a shell type definition.
psql:seg.sql:15: NOTICE: argument type seg is only a shell
RESET client_min_messages;
--
-- testing the input and output functions
--
@@ -814,49 +813,49 @@ SELECT '2 .. 3'::seg >> '0 .. 1'::seg AS bool;
-- "contained in" (the left value belongs within the interval specified in the right value):
--
SELECT '0'::seg ~ '0'::seg AS bool;
SELECT '0'::seg <@ '0'::seg AS bool;
bool
------
t
(1 row)
SELECT '0'::seg ~ '0 ..'::seg AS bool;
SELECT '0'::seg <@ '0 ..'::seg AS bool;
bool
------
t
(1 row)
SELECT '0'::seg ~ '.. 0'::seg AS bool;
SELECT '0'::seg <@ '.. 0'::seg AS bool;
bool
------
t
(1 row)
SELECT '0'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '0'::seg <@ '-1 .. 1'::seg AS bool;
bool
------
t
(1 row)
SELECT '0'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '0'::seg <@ '-1 .. 1'::seg AS bool;
bool
------
t
(1 row)
SELECT '-1'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '-1'::seg <@ '-1 .. 1'::seg AS bool;
bool
------
t
(1 row)
SELECT '1'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '1'::seg <@ '-1 .. 1'::seg AS bool;
bool
------
t
(1 row)
SELECT '-1 .. 1'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '-1 .. 1'::seg <@ '-1 .. 1'::seg AS bool;
bool
------
t
@@ -864,43 +863,43 @@ SELECT '-1 .. 1'::seg ~ '-1 .. 1'::seg AS bool;
-- "contains" (the left value contains the interval specified in the right value):
--
SELECT '0'::seg @ '0'::seg AS bool;
SELECT '0'::seg @> '0'::seg AS bool;
bool
------
t
(1 row)
SELECT '0 .. '::seg ~ '0'::seg AS bool;
SELECT '0 .. '::seg <@ '0'::seg AS bool;
bool
------
f
(1 row)
SELECT '.. 0'::seg ~ '0'::seg AS bool;
SELECT '.. 0'::seg <@ '0'::seg AS bool;
bool
------
f
(1 row)
SELECT '-1 .. 1'::seg ~ '0'::seg AS bool;
SELECT '-1 .. 1'::seg <@ '0'::seg AS bool;
bool
------
f
(1 row)
SELECT '0'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '0'::seg <@ '-1 .. 1'::seg AS bool;
bool
------
t
(1 row)
SELECT '-1'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '-1'::seg <@ '-1 .. 1'::seg AS bool;
bool
------
t
(1 row)
SELECT '1'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '1'::seg <@ '-1 .. 1'::seg AS bool;
bool
------
t
@@ -911,14 +910,14 @@ SELECT '1'::seg ~ '-1 .. 1'::seg AS bool;
CREATE TABLE test_seg (s seg);
\copy test_seg from 'data/test_seg.data'
CREATE INDEX test_seg_ix ON test_seg USING gist (s);
SELECT count(*) FROM test_seg WHERE s @ '11..11.3';
SELECT count(*) FROM test_seg WHERE s @> '11..11.3';
count
-------
143
(1 row)
-- Test sorting
SELECT * FROM test_seg WHERE s @ '11..11.3' GROUP BY s;
SELECT * FROM test_seg WHERE s @> '11..11.3' GROUP BY s;
s
-----------------
.. 4.0e1

View File

@@ -5,10 +5,9 @@
-- first, define the datatype. Turn off echoing so that expected file
-- does not depend on contents of seg.sql.
--
SET client_min_messages = warning;
\set ECHO none
psql:seg.sql:10: NOTICE: type "seg" is not yet defined
DETAIL: Creating a shell type definition.
psql:seg.sql:15: NOTICE: argument type seg is only a shell
RESET client_min_messages;
--
-- testing the input and output functions
--
@@ -814,49 +813,49 @@ SELECT '2 .. 3'::seg >> '0 .. 1'::seg AS bool;
-- "contained in" (the left value belongs within the interval specified in the right value):
--
SELECT '0'::seg ~ '0'::seg AS bool;
SELECT '0'::seg <@ '0'::seg AS bool;
bool
------
t
(1 row)
SELECT '0'::seg ~ '0 ..'::seg AS bool;
SELECT '0'::seg <@ '0 ..'::seg AS bool;
bool
------
t
(1 row)
SELECT '0'::seg ~ '.. 0'::seg AS bool;
SELECT '0'::seg <@ '.. 0'::seg AS bool;
bool
------
t
(1 row)
SELECT '0'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '0'::seg <@ '-1 .. 1'::seg AS bool;
bool
------
t
(1 row)
SELECT '0'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '0'::seg <@ '-1 .. 1'::seg AS bool;
bool
------
t
(1 row)
SELECT '-1'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '-1'::seg <@ '-1 .. 1'::seg AS bool;
bool
------
t
(1 row)
SELECT '1'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '1'::seg <@ '-1 .. 1'::seg AS bool;
bool
------
t
(1 row)
SELECT '-1 .. 1'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '-1 .. 1'::seg <@ '-1 .. 1'::seg AS bool;
bool
------
t
@@ -864,43 +863,43 @@ SELECT '-1 .. 1'::seg ~ '-1 .. 1'::seg AS bool;
-- "contains" (the left value contains the interval specified in the right value):
--
SELECT '0'::seg @ '0'::seg AS bool;
SELECT '0'::seg @> '0'::seg AS bool;
bool
------
t
(1 row)
SELECT '0 .. '::seg ~ '0'::seg AS bool;
SELECT '0 .. '::seg <@ '0'::seg AS bool;
bool
------
f
(1 row)
SELECT '.. 0'::seg ~ '0'::seg AS bool;
SELECT '.. 0'::seg <@ '0'::seg AS bool;
bool
------
f
(1 row)
SELECT '-1 .. 1'::seg ~ '0'::seg AS bool;
SELECT '-1 .. 1'::seg <@ '0'::seg AS bool;
bool
------
f
(1 row)
SELECT '0'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '0'::seg <@ '-1 .. 1'::seg AS bool;
bool
------
t
(1 row)
SELECT '-1'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '-1'::seg <@ '-1 .. 1'::seg AS bool;
bool
------
t
(1 row)
SELECT '1'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '1'::seg <@ '-1 .. 1'::seg AS bool;
bool
------
t
@@ -911,14 +910,14 @@ SELECT '1'::seg ~ '-1 .. 1'::seg AS bool;
CREATE TABLE test_seg (s seg);
\copy test_seg from 'data/test_seg.data'
CREATE INDEX test_seg_ix ON test_seg USING gist (s);
SELECT count(*) FROM test_seg WHERE s @ '11..11.3';
SELECT count(*) FROM test_seg WHERE s @> '11..11.3';
count
-------
143
(1 row)
-- Test sorting
SELECT * FROM test_seg WHERE s @ '11..11.3' GROUP BY s;
SELECT * FROM test_seg WHERE s @> '11..11.3' GROUP BY s;
s
-----------------
.. 4.0e1

View File

@@ -492,9 +492,11 @@ gseg_leaf_consistent(SEG * key,
retval = (bool) seg_same(key, query);
break;
case RTContainsStrategyNumber:
case RTOldContainsStrategyNumber:
retval = (bool) seg_contains(key, query);
break;
case RTContainedByStrategyNumber:
case RTOldContainedByStrategyNumber:
retval = (bool) seg_contained(key, query);
break;
default:
@@ -533,9 +535,11 @@ gseg_internal_consistent(SEG * key,
break;
case RTSameStrategyNumber:
case RTContainsStrategyNumber:
case RTOldContainsStrategyNumber:
retval = (bool) seg_contains(key, query);
break;
case RTContainedByStrategyNumber:
case RTOldContainedByStrategyNumber:
retval = (bool) seg_overlap(key, query);
break;
default:

View File

@@ -281,6 +281,25 @@ CREATE OPERATOR <> (
JOIN = neqjoinsel
);
CREATE OPERATOR @> (
LEFTARG = seg,
RIGHTARG = seg,
PROCEDURE = seg_contains,
COMMUTATOR = '<@',
RESTRICT = contsel,
JOIN = contjoinsel
);
CREATE OPERATOR <@ (
LEFTARG = seg,
RIGHTARG = seg,
PROCEDURE = seg_contained,
COMMUTATOR = '@>',
RESTRICT = contsel,
JOIN = contjoinsel
);
-- obsolete:
CREATE OPERATOR @ (
LEFTARG = seg,
RIGHTARG = seg,
@@ -357,8 +376,10 @@ AS
OPERATOR 4 &> ,
OPERATOR 5 >> ,
OPERATOR 6 = ,
OPERATOR 7 @ ,
OPERATOR 8 ~ ,
OPERATOR 7 @> ,
OPERATOR 8 <@ ,
OPERATOR 13 @ ,
OPERATOR 14 ~ ,
FUNCTION 1 gseg_consistent (internal, seg, int4),
FUNCTION 2 gseg_union (internal, internal),
FUNCTION 3 gseg_compress (internal),

View File

@@ -6,9 +6,11 @@
-- first, define the datatype. Turn off echoing so that expected file
-- does not depend on contents of seg.sql.
--
SET client_min_messages = warning;
\set ECHO none
\i seg.sql
\set ECHO all
RESET client_min_messages;
--
-- testing the input and output functions
@@ -191,24 +193,24 @@ SELECT '2 .. 3'::seg >> '0 .. 1'::seg AS bool;
-- "contained in" (the left value belongs within the interval specified in the right value):
--
SELECT '0'::seg ~ '0'::seg AS bool;
SELECT '0'::seg ~ '0 ..'::seg AS bool;
SELECT '0'::seg ~ '.. 0'::seg AS bool;
SELECT '0'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '0'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '-1'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '1'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '-1 .. 1'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '0'::seg <@ '0'::seg AS bool;
SELECT '0'::seg <@ '0 ..'::seg AS bool;
SELECT '0'::seg <@ '.. 0'::seg AS bool;
SELECT '0'::seg <@ '-1 .. 1'::seg AS bool;
SELECT '0'::seg <@ '-1 .. 1'::seg AS bool;
SELECT '-1'::seg <@ '-1 .. 1'::seg AS bool;
SELECT '1'::seg <@ '-1 .. 1'::seg AS bool;
SELECT '-1 .. 1'::seg <@ '-1 .. 1'::seg AS bool;
-- "contains" (the left value contains the interval specified in the right value):
--
SELECT '0'::seg @ '0'::seg AS bool;
SELECT '0 .. '::seg ~ '0'::seg AS bool;
SELECT '.. 0'::seg ~ '0'::seg AS bool;
SELECT '-1 .. 1'::seg ~ '0'::seg AS bool;
SELECT '0'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '-1'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '1'::seg ~ '-1 .. 1'::seg AS bool;
SELECT '0'::seg @> '0'::seg AS bool;
SELECT '0 .. '::seg <@ '0'::seg AS bool;
SELECT '.. 0'::seg <@ '0'::seg AS bool;
SELECT '-1 .. 1'::seg <@ '0'::seg AS bool;
SELECT '0'::seg <@ '-1 .. 1'::seg AS bool;
SELECT '-1'::seg <@ '-1 .. 1'::seg AS bool;
SELECT '1'::seg <@ '-1 .. 1'::seg AS bool;
-- Load some example data and build the index
--
@@ -217,7 +219,7 @@ CREATE TABLE test_seg (s seg);
\copy test_seg from 'data/test_seg.data'
CREATE INDEX test_seg_ix ON test_seg USING gist (s);
SELECT count(*) FROM test_seg WHERE s @ '11..11.3';
SELECT count(*) FROM test_seg WHERE s @> '11..11.3';
-- Test sorting
SELECT * FROM test_seg WHERE s @ '11..11.3' GROUP BY s;
SELECT * FROM test_seg WHERE s @> '11..11.3' GROUP BY s;

View File

@@ -18,6 +18,10 @@ DROP FUNCTION gseg_compress(internal);
DROP FUNCTION gseg_consistent(internal,seg,int4);
DROP OPERATOR <@ (seg, seg);
DROP OPERATOR @> (seg, seg);
DROP OPERATOR ~ (seg, seg);
DROP OPERATOR @ (seg, seg);