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

@ -201,14 +201,20 @@ a && b Overlaps
The cubements a and b overlap.
a @ b Contains
a @> b Contains
The cubement a contains the cubement b.
a ~ b Contained in
a <@ b Contained in
The cubement a is contained in b.
(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

@ -1,5 +1,5 @@
/******************************************************************************
$PostgreSQL: pgsql/contrib/cube/cube.c,v 1.28 2006/07/27 21:55:09 tgl Exp $
$PostgreSQL: pgsql/contrib/cube/cube.c,v 1.29 2006/09/10 17:36:50 tgl Exp $
This file contains routines that can be bound to a Postgres backend and
called by the backend in the process of processing queries. The calling
@ -689,9 +689,11 @@ g_cube_leaf_consistent(NDBOX * key,
retval = (bool) (cube_cmp_v0(key, query) == 0);
break;
case RTContainsStrategyNumber:
case RTOldContainsStrategyNumber:
retval = (bool) cube_contains_v0(key, query);
break;
case RTContainedByStrategyNumber:
case RTOldContainedByStrategyNumber:
retval = (bool) cube_contains_v0(query, key);
break;
default:
@ -717,9 +719,11 @@ g_cube_internal_consistent(NDBOX * key,
break;
case RTSameStrategyNumber:
case RTContainsStrategyNumber:
case RTOldContainsStrategyNumber:
retval = (bool) cube_contains_v0(key, query);
break;
case RTContainedByStrategyNumber:
case RTOldContainedByStrategyNumber:
retval = (bool) cube_overlap_v0(key, query);
break;
default:

View File

@ -243,6 +243,19 @@ CREATE OPERATOR <> (
RESTRICT = neqsel, JOIN = neqjoinsel
);
CREATE OPERATOR @> (
LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_contains,
COMMUTATOR = '<@',
RESTRICT = contsel, JOIN = contjoinsel
);
CREATE OPERATOR <@ (
LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_contained,
COMMUTATOR = '@>',
RESTRICT = contsel, JOIN = contjoinsel
);
-- these are obsolete/deprecated:
CREATE OPERATOR @ (
LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_contains,
COMMUTATOR = '~',
@ -308,8 +321,10 @@ CREATE OPERATOR CLASS gist_cube_ops
DEFAULT FOR TYPE cube USING gist AS
OPERATOR 3 && ,
OPERATOR 6 = ,
OPERATOR 7 @ ,
OPERATOR 8 ~ ,
OPERATOR 7 @> ,
OPERATOR 8 <@ ,
OPERATOR 13 @ ,
OPERATOR 14 ~ ,
FUNCTION 1 g_cube_consistent (internal, cube, int4),
FUNCTION 2 g_cube_union (internal, internal),
FUNCTION 3 g_cube_compress (internal),

View File

@ -627,91 +627,91 @@ SELECT '[(-1,-1,-1),(1,1,1)]'::cube && '[(2,1,1),(2,2,2)]'::cube AS bool;
-- "contained in" (the left operand is the cube entirely enclosed by
-- the right operand):
--
SELECT '0'::cube ~ '0'::cube AS bool;
SELECT '0'::cube <@ '0'::cube AS bool;
bool
------
t
(1 row)
SELECT '0,0,0'::cube ~ '0,0,0'::cube AS bool;
SELECT '0,0,0'::cube <@ '0,0,0'::cube AS bool;
bool
------
t
(1 row)
SELECT '0,0'::cube ~ '0,0,1'::cube AS bool;
SELECT '0,0'::cube <@ '0,0,1'::cube AS bool;
bool
------
t
(1 row)
SELECT '0,0,0'::cube ~ '0,0,1'::cube AS bool;
SELECT '0,0,0'::cube <@ '0,0,1'::cube AS bool;
bool
------
f
(1 row)
SELECT '1,0,0'::cube ~ '0,0,1'::cube AS bool;
SELECT '1,0,0'::cube <@ '0,0,1'::cube AS bool;
bool
------
f
(1 row)
SELECT '(1,0,0),(0,0,1)'::cube ~ '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube <@ '(1,0,0),(0,0,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(1,0,0),(0,0,1)'::cube ~ '(-1,-1,-1),(1,1,1)'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube <@ '(-1,-1,-1),(1,1,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(1,0,0),(0,0,1)'::cube ~ '(-1,-1,-1,-1),(1,1,1,1)'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube <@ '(-1,-1,-1,-1),(1,1,1,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '0'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '0'::cube <@ '(-1),(1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '1'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '1'::cube <@ '(-1),(1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '-1'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '-1'::cube <@ '(-1),(1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '(-1),(1)'::cube <@ '(-1),(1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube ~ '(-1,-1),(1,1)'::cube AS bool;
SELECT '(-1),(1)'::cube <@ '(-1,-1),(1,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-2),(1)'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '(-2),(1)'::cube <@ '(-1),(1)'::cube AS bool;
bool
------
f
(1 row)
SELECT '(-2),(1)'::cube ~ '(-1,-1),(1,1)'::cube AS bool;
SELECT '(-2),(1)'::cube <@ '(-1,-1),(1,1)'::cube AS bool;
bool
------
f
@ -720,91 +720,91 @@ SELECT '(-2),(1)'::cube ~ '(-1,-1),(1,1)'::cube AS bool;
-- "contains" (the left operand is the cube that entirely encloses the
-- right operand)
--
SELECT '0'::cube @ '0'::cube AS bool;
SELECT '0'::cube @> '0'::cube AS bool;
bool
------
t
(1 row)
SELECT '0,0,0'::cube @ '0,0,0'::cube AS bool;
SELECT '0,0,0'::cube @> '0,0,0'::cube AS bool;
bool
------
t
(1 row)
SELECT '0,0,1'::cube @ '0,0'::cube AS bool;
SELECT '0,0,1'::cube @> '0,0'::cube AS bool;
bool
------
t
(1 row)
SELECT '0,0,1'::cube @ '0,0,0'::cube AS bool;
SELECT '0,0,1'::cube @> '0,0,0'::cube AS bool;
bool
------
f
(1 row)
SELECT '0,0,1'::cube @ '1,0,0'::cube AS bool;
SELECT '0,0,1'::cube @> '1,0,0'::cube AS bool;
bool
------
f
(1 row)
SELECT '(1,0,0),(0,0,1)'::cube @ '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube @> '(1,0,0),(0,0,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1,-1,-1),(1,1,1)'::cube @ '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(-1,-1,-1),(1,1,1)'::cube @> '(1,0,0),(0,0,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1,-1,-1,-1),(1,1,1,1)'::cube @ '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(-1,-1,-1,-1),(1,1,1,1)'::cube @> '(1,0,0),(0,0,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube @ '0'::cube AS bool;
SELECT '(-1),(1)'::cube @> '0'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube @ '1'::cube AS bool;
SELECT '(-1),(1)'::cube @> '1'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube @ '-1'::cube AS bool;
SELECT '(-1),(1)'::cube @> '-1'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube @ '(-1),(1)'::cube AS bool;
SELECT '(-1),(1)'::cube @> '(-1),(1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1,-1),(1,1)'::cube @ '(-1),(1)'::cube AS bool;
SELECT '(-1,-1),(1,1)'::cube @> '(-1),(1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube @ '(-2),(1)'::cube AS bool;
SELECT '(-1),(1)'::cube @> '(-2),(1)'::cube AS bool;
bool
------
f
(1 row)
SELECT '(-1,-1),(1,1)'::cube @ '(-2),(1)'::cube AS bool;
SELECT '(-1,-1),(1,1)'::cube @> '(-2),(1)'::cube AS bool;
bool
------
f

View File

@ -627,91 +627,91 @@ SELECT '[(-1,-1,-1),(1,1,1)]'::cube && '[(2,1,1),(2,2,2)]'::cube AS bool;
-- "contained in" (the left operand is the cube entirely enclosed by
-- the right operand):
--
SELECT '0'::cube ~ '0'::cube AS bool;
SELECT '0'::cube <@ '0'::cube AS bool;
bool
------
t
(1 row)
SELECT '0,0,0'::cube ~ '0,0,0'::cube AS bool;
SELECT '0,0,0'::cube <@ '0,0,0'::cube AS bool;
bool
------
t
(1 row)
SELECT '0,0'::cube ~ '0,0,1'::cube AS bool;
SELECT '0,0'::cube <@ '0,0,1'::cube AS bool;
bool
------
t
(1 row)
SELECT '0,0,0'::cube ~ '0,0,1'::cube AS bool;
SELECT '0,0,0'::cube <@ '0,0,1'::cube AS bool;
bool
------
f
(1 row)
SELECT '1,0,0'::cube ~ '0,0,1'::cube AS bool;
SELECT '1,0,0'::cube <@ '0,0,1'::cube AS bool;
bool
------
f
(1 row)
SELECT '(1,0,0),(0,0,1)'::cube ~ '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube <@ '(1,0,0),(0,0,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(1,0,0),(0,0,1)'::cube ~ '(-1,-1,-1),(1,1,1)'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube <@ '(-1,-1,-1),(1,1,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(1,0,0),(0,0,1)'::cube ~ '(-1,-1,-1,-1),(1,1,1,1)'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube <@ '(-1,-1,-1,-1),(1,1,1,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '0'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '0'::cube <@ '(-1),(1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '1'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '1'::cube <@ '(-1),(1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '-1'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '-1'::cube <@ '(-1),(1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '(-1),(1)'::cube <@ '(-1),(1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube ~ '(-1,-1),(1,1)'::cube AS bool;
SELECT '(-1),(1)'::cube <@ '(-1,-1),(1,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-2),(1)'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '(-2),(1)'::cube <@ '(-1),(1)'::cube AS bool;
bool
------
f
(1 row)
SELECT '(-2),(1)'::cube ~ '(-1,-1),(1,1)'::cube AS bool;
SELECT '(-2),(1)'::cube <@ '(-1,-1),(1,1)'::cube AS bool;
bool
------
f
@ -720,91 +720,91 @@ SELECT '(-2),(1)'::cube ~ '(-1,-1),(1,1)'::cube AS bool;
-- "contains" (the left operand is the cube that entirely encloses the
-- right operand)
--
SELECT '0'::cube @ '0'::cube AS bool;
SELECT '0'::cube @> '0'::cube AS bool;
bool
------
t
(1 row)
SELECT '0,0,0'::cube @ '0,0,0'::cube AS bool;
SELECT '0,0,0'::cube @> '0,0,0'::cube AS bool;
bool
------
t
(1 row)
SELECT '0,0,1'::cube @ '0,0'::cube AS bool;
SELECT '0,0,1'::cube @> '0,0'::cube AS bool;
bool
------
t
(1 row)
SELECT '0,0,1'::cube @ '0,0,0'::cube AS bool;
SELECT '0,0,1'::cube @> '0,0,0'::cube AS bool;
bool
------
f
(1 row)
SELECT '0,0,1'::cube @ '1,0,0'::cube AS bool;
SELECT '0,0,1'::cube @> '1,0,0'::cube AS bool;
bool
------
f
(1 row)
SELECT '(1,0,0),(0,0,1)'::cube @ '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube @> '(1,0,0),(0,0,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1,-1,-1),(1,1,1)'::cube @ '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(-1,-1,-1),(1,1,1)'::cube @> '(1,0,0),(0,0,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1,-1,-1,-1),(1,1,1,1)'::cube @ '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(-1,-1,-1,-1),(1,1,1,1)'::cube @> '(1,0,0),(0,0,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube @ '0'::cube AS bool;
SELECT '(-1),(1)'::cube @> '0'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube @ '1'::cube AS bool;
SELECT '(-1),(1)'::cube @> '1'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube @ '-1'::cube AS bool;
SELECT '(-1),(1)'::cube @> '-1'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube @ '(-1),(1)'::cube AS bool;
SELECT '(-1),(1)'::cube @> '(-1),(1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1,-1),(1,1)'::cube @ '(-1),(1)'::cube AS bool;
SELECT '(-1,-1),(1,1)'::cube @> '(-1),(1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube @ '(-2),(1)'::cube AS bool;
SELECT '(-1),(1)'::cube @> '(-2),(1)'::cube AS bool;
bool
------
f
(1 row)
SELECT '(-1,-1),(1,1)'::cube @ '(-2),(1)'::cube AS bool;
SELECT '(-1,-1),(1,1)'::cube @> '(-2),(1)'::cube AS bool;
bool
------
f

View File

@ -627,91 +627,91 @@ SELECT '[(-1,-1,-1),(1,1,1)]'::cube && '[(2,1,1),(2,2,2)]'::cube AS bool;
-- "contained in" (the left operand is the cube entirely enclosed by
-- the right operand):
--
SELECT '0'::cube ~ '0'::cube AS bool;
SELECT '0'::cube <@ '0'::cube AS bool;
bool
------
t
(1 row)
SELECT '0,0,0'::cube ~ '0,0,0'::cube AS bool;
SELECT '0,0,0'::cube <@ '0,0,0'::cube AS bool;
bool
------
t
(1 row)
SELECT '0,0'::cube ~ '0,0,1'::cube AS bool;
SELECT '0,0'::cube <@ '0,0,1'::cube AS bool;
bool
------
t
(1 row)
SELECT '0,0,0'::cube ~ '0,0,1'::cube AS bool;
SELECT '0,0,0'::cube <@ '0,0,1'::cube AS bool;
bool
------
f
(1 row)
SELECT '1,0,0'::cube ~ '0,0,1'::cube AS bool;
SELECT '1,0,0'::cube <@ '0,0,1'::cube AS bool;
bool
------
f
(1 row)
SELECT '(1,0,0),(0,0,1)'::cube ~ '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube <@ '(1,0,0),(0,0,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(1,0,0),(0,0,1)'::cube ~ '(-1,-1,-1),(1,1,1)'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube <@ '(-1,-1,-1),(1,1,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(1,0,0),(0,0,1)'::cube ~ '(-1,-1,-1,-1),(1,1,1,1)'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube <@ '(-1,-1,-1,-1),(1,1,1,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '0'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '0'::cube <@ '(-1),(1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '1'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '1'::cube <@ '(-1),(1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '-1'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '-1'::cube <@ '(-1),(1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '(-1),(1)'::cube <@ '(-1),(1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube ~ '(-1,-1),(1,1)'::cube AS bool;
SELECT '(-1),(1)'::cube <@ '(-1,-1),(1,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-2),(1)'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '(-2),(1)'::cube <@ '(-1),(1)'::cube AS bool;
bool
------
f
(1 row)
SELECT '(-2),(1)'::cube ~ '(-1,-1),(1,1)'::cube AS bool;
SELECT '(-2),(1)'::cube <@ '(-1,-1),(1,1)'::cube AS bool;
bool
------
f
@ -720,91 +720,91 @@ SELECT '(-2),(1)'::cube ~ '(-1,-1),(1,1)'::cube AS bool;
-- "contains" (the left operand is the cube that entirely encloses the
-- right operand)
--
SELECT '0'::cube @ '0'::cube AS bool;
SELECT '0'::cube @> '0'::cube AS bool;
bool
------
t
(1 row)
SELECT '0,0,0'::cube @ '0,0,0'::cube AS bool;
SELECT '0,0,0'::cube @> '0,0,0'::cube AS bool;
bool
------
t
(1 row)
SELECT '0,0,1'::cube @ '0,0'::cube AS bool;
SELECT '0,0,1'::cube @> '0,0'::cube AS bool;
bool
------
t
(1 row)
SELECT '0,0,1'::cube @ '0,0,0'::cube AS bool;
SELECT '0,0,1'::cube @> '0,0,0'::cube AS bool;
bool
------
f
(1 row)
SELECT '0,0,1'::cube @ '1,0,0'::cube AS bool;
SELECT '0,0,1'::cube @> '1,0,0'::cube AS bool;
bool
------
f
(1 row)
SELECT '(1,0,0),(0,0,1)'::cube @ '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube @> '(1,0,0),(0,0,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1,-1,-1),(1,1,1)'::cube @ '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(-1,-1,-1),(1,1,1)'::cube @> '(1,0,0),(0,0,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1,-1,-1,-1),(1,1,1,1)'::cube @ '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(-1,-1,-1,-1),(1,1,1,1)'::cube @> '(1,0,0),(0,0,1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube @ '0'::cube AS bool;
SELECT '(-1),(1)'::cube @> '0'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube @ '1'::cube AS bool;
SELECT '(-1),(1)'::cube @> '1'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube @ '-1'::cube AS bool;
SELECT '(-1),(1)'::cube @> '-1'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube @ '(-1),(1)'::cube AS bool;
SELECT '(-1),(1)'::cube @> '(-1),(1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1,-1),(1,1)'::cube @ '(-1),(1)'::cube AS bool;
SELECT '(-1,-1),(1,1)'::cube @> '(-1),(1)'::cube AS bool;
bool
------
t
(1 row)
SELECT '(-1),(1)'::cube @ '(-2),(1)'::cube AS bool;
SELECT '(-1),(1)'::cube @> '(-2),(1)'::cube AS bool;
bool
------
f
(1 row)
SELECT '(-1,-1),(1,1)'::cube @ '(-2),(1)'::cube AS bool;
SELECT '(-1,-1),(1,1)'::cube @> '(-2),(1)'::cube AS bool;
bool
------
f

View File

@ -180,41 +180,41 @@ SELECT '[(-1,-1,-1),(1,1,1)]'::cube && '[(2,1,1),(2,2,2)]'::cube AS bool;
-- "contained in" (the left operand is the cube entirely enclosed by
-- the right operand):
--
SELECT '0'::cube ~ '0'::cube AS bool;
SELECT '0,0,0'::cube ~ '0,0,0'::cube AS bool;
SELECT '0,0'::cube ~ '0,0,1'::cube AS bool;
SELECT '0,0,0'::cube ~ '0,0,1'::cube AS bool;
SELECT '1,0,0'::cube ~ '0,0,1'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube ~ '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube ~ '(-1,-1,-1),(1,1,1)'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube ~ '(-1,-1,-1,-1),(1,1,1,1)'::cube AS bool;
SELECT '0'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '1'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '-1'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '(-1),(1)'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '(-1),(1)'::cube ~ '(-1,-1),(1,1)'::cube AS bool;
SELECT '(-2),(1)'::cube ~ '(-1),(1)'::cube AS bool;
SELECT '(-2),(1)'::cube ~ '(-1,-1),(1,1)'::cube AS bool;
SELECT '0'::cube <@ '0'::cube AS bool;
SELECT '0,0,0'::cube <@ '0,0,0'::cube AS bool;
SELECT '0,0'::cube <@ '0,0,1'::cube AS bool;
SELECT '0,0,0'::cube <@ '0,0,1'::cube AS bool;
SELECT '1,0,0'::cube <@ '0,0,1'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube <@ '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube <@ '(-1,-1,-1),(1,1,1)'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube <@ '(-1,-1,-1,-1),(1,1,1,1)'::cube AS bool;
SELECT '0'::cube <@ '(-1),(1)'::cube AS bool;
SELECT '1'::cube <@ '(-1),(1)'::cube AS bool;
SELECT '-1'::cube <@ '(-1),(1)'::cube AS bool;
SELECT '(-1),(1)'::cube <@ '(-1),(1)'::cube AS bool;
SELECT '(-1),(1)'::cube <@ '(-1,-1),(1,1)'::cube AS bool;
SELECT '(-2),(1)'::cube <@ '(-1),(1)'::cube AS bool;
SELECT '(-2),(1)'::cube <@ '(-1,-1),(1,1)'::cube AS bool;
-- "contains" (the left operand is the cube that entirely encloses the
-- right operand)
--
SELECT '0'::cube @ '0'::cube AS bool;
SELECT '0,0,0'::cube @ '0,0,0'::cube AS bool;
SELECT '0,0,1'::cube @ '0,0'::cube AS bool;
SELECT '0,0,1'::cube @ '0,0,0'::cube AS bool;
SELECT '0,0,1'::cube @ '1,0,0'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube @ '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(-1,-1,-1),(1,1,1)'::cube @ '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(-1,-1,-1,-1),(1,1,1,1)'::cube @ '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(-1),(1)'::cube @ '0'::cube AS bool;
SELECT '(-1),(1)'::cube @ '1'::cube AS bool;
SELECT '(-1),(1)'::cube @ '-1'::cube AS bool;
SELECT '(-1),(1)'::cube @ '(-1),(1)'::cube AS bool;
SELECT '(-1,-1),(1,1)'::cube @ '(-1),(1)'::cube AS bool;
SELECT '(-1),(1)'::cube @ '(-2),(1)'::cube AS bool;
SELECT '(-1,-1),(1,1)'::cube @ '(-2),(1)'::cube AS bool;
SELECT '0'::cube @> '0'::cube AS bool;
SELECT '0,0,0'::cube @> '0,0,0'::cube AS bool;
SELECT '0,0,1'::cube @> '0,0'::cube AS bool;
SELECT '0,0,1'::cube @> '0,0,0'::cube AS bool;
SELECT '0,0,1'::cube @> '1,0,0'::cube AS bool;
SELECT '(1,0,0),(0,0,1)'::cube @> '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(-1,-1,-1),(1,1,1)'::cube @> '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(-1,-1,-1,-1),(1,1,1,1)'::cube @> '(1,0,0),(0,0,1)'::cube AS bool;
SELECT '(-1),(1)'::cube @> '0'::cube AS bool;
SELECT '(-1),(1)'::cube @> '1'::cube AS bool;
SELECT '(-1),(1)'::cube @> '-1'::cube AS bool;
SELECT '(-1),(1)'::cube @> '(-1),(1)'::cube AS bool;
SELECT '(-1,-1),(1,1)'::cube @> '(-1),(1)'::cube AS bool;
SELECT '(-1),(1)'::cube @> '(-2),(1)'::cube AS bool;
SELECT '(-1,-1),(1,1)'::cube @> '(-2),(1)'::cube AS bool;
-- Test of distance function
--

View File

@ -22,6 +22,10 @@ DROP OPERATOR ~ (cube, cube);
DROP OPERATOR @ (cube, cube);
DROP OPERATOR <@ (cube, cube);
DROP OPERATOR @> (cube, cube);
DROP OPERATOR <> (cube, cube);
DROP OPERATOR = (cube, cube);

View File

@ -78,7 +78,7 @@ earth_distance(earth, earth) - Returns the great circle distance between
two points on the surface of the Earth.
earth_box(earth, float8) - Returns a box suitable for an indexed search using
the cube @ operator for points within a given great circle distance of a
the cube @> operator for points within a given great circle distance of a
location. Some points in this box are further than the specified great circle
distance from the location so a second check using earth_distance should be
made at the same time.

View File

@ -743,7 +743,7 @@ SELECT cube_ll_coord(earth_box(ll_to_earth(0,0),10*earth()),1)::numeric(20,5),
-- Test for points that should be in bounding boxes.
--
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,1))*1.00001) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,1))*1.00001) @>
ll_to_earth(0,1);
?column?
----------
@ -751,7 +751,7 @@ SELECT earth_box(ll_to_earth(0,0),
(1 row)
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.1))*1.00001) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.1))*1.00001) @>
ll_to_earth(0,0.1);
?column?
----------
@ -759,7 +759,7 @@ SELECT earth_box(ll_to_earth(0,0),
(1 row)
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.01))*1.00001) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.01))*1.00001) @>
ll_to_earth(0,0.01);
?column?
----------
@ -767,7 +767,7 @@ SELECT earth_box(ll_to_earth(0,0),
(1 row)
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.001))*1.00001) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.001))*1.00001) @>
ll_to_earth(0,0.001);
?column?
----------
@ -775,7 +775,7 @@ SELECT earth_box(ll_to_earth(0,0),
(1 row)
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.0001))*1.00001) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.0001))*1.00001) @>
ll_to_earth(0,0.0001);
?column?
----------
@ -783,7 +783,7 @@ SELECT earth_box(ll_to_earth(0,0),
(1 row)
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0.0001,0.0001))*1.00001) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0.0001,0.0001))*1.00001) @>
ll_to_earth(0.0001,0.0001);
?column?
----------
@ -791,7 +791,7 @@ SELECT earth_box(ll_to_earth(0,0),
(1 row)
SELECT earth_box(ll_to_earth(45,45),
earth_distance(ll_to_earth(45,45),ll_to_earth(45.0001,45.0001))*1.00001) @
earth_distance(ll_to_earth(45,45),ll_to_earth(45.0001,45.0001))*1.00001) @>
ll_to_earth(45.0001,45.0001);
?column?
----------
@ -799,7 +799,7 @@ SELECT earth_box(ll_to_earth(45,45),
(1 row)
SELECT earth_box(ll_to_earth(90,180),
earth_distance(ll_to_earth(90,180),ll_to_earth(90.0001,180.0001))*1.00001) @
earth_distance(ll_to_earth(90,180),ll_to_earth(90.0001,180.0001))*1.00001) @>
ll_to_earth(90.0001,180.0001);
?column?
----------
@ -812,7 +812,7 @@ SELECT earth_box(ll_to_earth(90,180),
-- but further away than the distance we are testing.
--
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,1))*.57735) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,1))*.57735) @>
ll_to_earth(0,1);
?column?
----------
@ -820,7 +820,7 @@ SELECT earth_box(ll_to_earth(0,0),
(1 row)
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.1))*.57735) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.1))*.57735) @>
ll_to_earth(0,0.1);
?column?
----------
@ -828,7 +828,7 @@ SELECT earth_box(ll_to_earth(0,0),
(1 row)
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.01))*.57735) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.01))*.57735) @>
ll_to_earth(0,0.01);
?column?
----------
@ -836,7 +836,7 @@ SELECT earth_box(ll_to_earth(0,0),
(1 row)
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.001))*.57735) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.001))*.57735) @>
ll_to_earth(0,0.001);
?column?
----------
@ -844,7 +844,7 @@ SELECT earth_box(ll_to_earth(0,0),
(1 row)
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.0001))*.57735) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.0001))*.57735) @>
ll_to_earth(0,0.0001);
?column?
----------
@ -852,7 +852,7 @@ SELECT earth_box(ll_to_earth(0,0),
(1 row)
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0.0001,0.0001))*.57735) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0.0001,0.0001))*.57735) @>
ll_to_earth(0.0001,0.0001);
?column?
----------
@ -860,7 +860,7 @@ SELECT earth_box(ll_to_earth(0,0),
(1 row)
SELECT earth_box(ll_to_earth(45,45),
earth_distance(ll_to_earth(45,45),ll_to_earth(45.0001,45.0001))*.57735) @
earth_distance(ll_to_earth(45,45),ll_to_earth(45.0001,45.0001))*.57735) @>
ll_to_earth(45.0001,45.0001);
?column?
----------
@ -868,7 +868,7 @@ SELECT earth_box(ll_to_earth(45,45),
(1 row)
SELECT earth_box(ll_to_earth(90,180),
earth_distance(ll_to_earth(90,180),ll_to_earth(90.0001,180.0001))*.57735) @
earth_distance(ll_to_earth(90,180),ll_to_earth(90.0001,180.0001))*.57735) @>
ll_to_earth(90.0001,180.0001);
?column?
----------

View File

@ -224,28 +224,28 @@ SELECT cube_ll_coord(earth_box(ll_to_earth(0,0),10*earth()),1)::numeric(20,5),
--
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,1))*1.00001) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,1))*1.00001) @>
ll_to_earth(0,1);
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.1))*1.00001) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.1))*1.00001) @>
ll_to_earth(0,0.1);
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.01))*1.00001) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.01))*1.00001) @>
ll_to_earth(0,0.01);
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.001))*1.00001) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.001))*1.00001) @>
ll_to_earth(0,0.001);
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.0001))*1.00001) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.0001))*1.00001) @>
ll_to_earth(0,0.0001);
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0.0001,0.0001))*1.00001) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0.0001,0.0001))*1.00001) @>
ll_to_earth(0.0001,0.0001);
SELECT earth_box(ll_to_earth(45,45),
earth_distance(ll_to_earth(45,45),ll_to_earth(45.0001,45.0001))*1.00001) @
earth_distance(ll_to_earth(45,45),ll_to_earth(45.0001,45.0001))*1.00001) @>
ll_to_earth(45.0001,45.0001);
SELECT earth_box(ll_to_earth(90,180),
earth_distance(ll_to_earth(90,180),ll_to_earth(90.0001,180.0001))*1.00001) @
earth_distance(ll_to_earth(90,180),ll_to_earth(90.0001,180.0001))*1.00001) @>
ll_to_earth(90.0001,180.0001);
--
@ -255,28 +255,28 @@ SELECT earth_box(ll_to_earth(90,180),
--
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,1))*.57735) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,1))*.57735) @>
ll_to_earth(0,1);
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.1))*.57735) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.1))*.57735) @>
ll_to_earth(0,0.1);
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.01))*.57735) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.01))*.57735) @>
ll_to_earth(0,0.01);
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.001))*.57735) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.001))*.57735) @>
ll_to_earth(0,0.001);
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.0001))*.57735) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.0001))*.57735) @>
ll_to_earth(0,0.0001);
SELECT earth_box(ll_to_earth(0,0),
earth_distance(ll_to_earth(0,0),ll_to_earth(0.0001,0.0001))*.57735) @
earth_distance(ll_to_earth(0,0),ll_to_earth(0.0001,0.0001))*.57735) @>
ll_to_earth(0.0001,0.0001);
SELECT earth_box(ll_to_earth(45,45),
earth_distance(ll_to_earth(45,45),ll_to_earth(45.0001,45.0001))*.57735) @
earth_distance(ll_to_earth(45,45),ll_to_earth(45.0001,45.0001))*.57735) @>
ll_to_earth(45.0001,45.0001);
SELECT earth_box(ll_to_earth(90,180),
earth_distance(ll_to_earth(90,180),ll_to_earth(90.0001,180.0001))*.57735) @
earth_distance(ll_to_earth(90,180),ll_to_earth(90.0001,180.0001))*.57735) @>
ll_to_earth(90.0001,180.0001);
--

View File

@ -46,23 +46,29 @@ select 'a'=>'b';
----------
"a"=>"b"
* hstore @ hstore - contains operation, check if left operand contains right.
* hstore @> hstore - contains operation, check if left operand contains right.
regression=# select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>c';
regression=# select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>c';
?column?
----------
f
(1 row)
regression=# select 'a=>b, b=>1, c=>NULL'::hstore @ 'b=>1';
regression=# select 'a=>b, b=>1, c=>NULL'::hstore @> 'b=>1';
?column?
----------
t
(1 row)
* hstore ~ hstore - contained operation, check if left operand is contained
* hstore <@ hstore - contained operation, check if left operand is contained
in right
(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!)
Functions
* akeys(hstore) - returns all keys from hstore as array
@ -129,7 +135,7 @@ regression=# select isdefined('a=>NULL','a');
Indices
Module provides index support for '@' and '~' operations.
Module provides index support for '@>' and '<@' operations.
create index hidx on testhstore using gist(h);

View File

@ -1,10 +1,11 @@
--
-- first, define the datatype. Turn off echoing so that expected file
-- does not depend on contents of hstore.sql.
--
SET client_min_messages = warning;
\set ECHO none
psql:hstore.sql:8: NOTICE: type "hstore" is not yet defined
DETAIL: Creating a shell type definition.
psql:hstore.sql:13: NOTICE: argument type hstore is only a shell
psql:hstore.sql:132: NOTICE: type "ghstore" is not yet defined
DETAIL: Creating a shell type definition.
psql:hstore.sql:137: NOTICE: argument type ghstore is only a shell
RESET client_min_messages;
set escape_string_warning=off;
--hstore;
select ''::hstore;
hstore
@ -483,50 +484,50 @@ select * from each('aaa=>bq, b=>NULL, ""=>1 ');
aaa | bq
(3 rows)
-- @
select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>NULL';
-- @>
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>NULL';
?column?
----------
t
(1 row)
select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>NULL, c=>NULL';
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>NULL, c=>NULL';
?column?
----------
t
(1 row)
select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>NULL, g=>NULL';
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>NULL, g=>NULL';
?column?
----------
f
(1 row)
select 'a=>b, b=>1, c=>NULL'::hstore @ 'g=>NULL';
select 'a=>b, b=>1, c=>NULL'::hstore @> 'g=>NULL';
?column?
----------
f
(1 row)
select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>c';
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>c';
?column?
----------
f
(1 row)
select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>b';
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b';
?column?
----------
t
(1 row)
select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>b, c=>NULL';
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b, c=>NULL';
?column?
----------
t
(1 row)
select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>b, c=>q';
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b, c=>q';
?column?
----------
f
@ -534,19 +535,19 @@ select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>b, c=>q';
CREATE TABLE testhstore (h hstore);
\copy testhstore from 'data/hstore.data'
select count(*) from testhstore where h @ 'wait=>NULL';
select count(*) from testhstore where h @> 'wait=>NULL';
count
-------
189
(1 row)
select count(*) from testhstore where h @ 'wait=>CC';
select count(*) from testhstore where h @> 'wait=>CC';
count
-------
15
(1 row)
select count(*) from testhstore where h @ 'wait=>CC, public=>t';
select count(*) from testhstore where h @> 'wait=>CC, public=>t';
count
-------
2
@ -554,19 +555,19 @@ select count(*) from testhstore where h @ 'wait=>CC, public=>t';
create index hidx on testhstore using gist(h);
set enable_seqscan=off;
select count(*) from testhstore where h @ 'wait=>NULL';
select count(*) from testhstore where h @> 'wait=>NULL';
count
-------
189
(1 row)
select count(*) from testhstore where h @ 'wait=>CC';
select count(*) from testhstore where h @> 'wait=>CC';
count
-------
15
(1 row)
select count(*) from testhstore where h @ 'wait=>CC, public=>t';
select count(*) from testhstore where h @> 'wait=>CC, public=>t';
count
-------
2

View File

@ -61,6 +61,30 @@ RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE 'C' with (isstrict,iscachable);
CREATE FUNCTION hs_contained(hstore,hstore)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE 'C' with (isstrict,iscachable);
CREATE OPERATOR @> (
LEFTARG = hstore,
RIGHTARG = hstore,
PROCEDURE = hs_contains,
COMMUTATOR = '<@',
RESTRICT = contsel,
JOIN = contjoinsel
);
CREATE OPERATOR <@ (
LEFTARG = hstore,
RIGHTARG = hstore,
PROCEDURE = hs_contained,
COMMUTATOR = '@>',
RESTRICT = contsel,
JOIN = contjoinsel
);
-- obsolete:
CREATE OPERATOR @ (
LEFTARG = hstore,
RIGHTARG = hstore,
@ -70,11 +94,6 @@ CREATE OPERATOR @ (
JOIN = contjoinsel
);
CREATE FUNCTION hs_contained(hstore,hstore)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE 'C' with (isstrict,iscachable);
CREATE OPERATOR ~ (
LEFTARG = hstore,
RIGHTARG = hstore,
@ -181,8 +200,10 @@ LANGUAGE 'C';
CREATE OPERATOR CLASS gist_hstore_ops
DEFAULT FOR TYPE hstore USING gist
AS
OPERATOR 7 @ RECHECK,
--OPERATOR 8 ~ RECHECK,
OPERATOR 7 @> RECHECK,
--OPERATOR 8 <@ RECHECK,
OPERATOR 13 @ RECHECK,
--OPERATOR 14 ~ RECHECK,
FUNCTION 1 ghstore_consistent (internal, internal, int4),
FUNCTION 2 ghstore_union (internal, internal),
FUNCTION 3 ghstore_compress (internal),

View File

@ -1,7 +1,15 @@
--
-- first, define the datatype. Turn off echoing so that expected file
-- does not depend on contents of hstore.sql.
--
SET client_min_messages = warning;
\set ECHO none
\i hstore.sql
set escape_string_warning=off;
\set ECHO all
RESET client_min_messages;
set escape_string_warning=off;
--hstore;
select ''::hstore;
@ -103,29 +111,29 @@ select * from svals('');
select * from each('aaa=>bq, b=>NULL, ""=>1 ');
-- @
select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>NULL';
select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>NULL, c=>NULL';
select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>NULL, g=>NULL';
select 'a=>b, b=>1, c=>NULL'::hstore @ 'g=>NULL';
select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>c';
select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>b';
select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>b, c=>NULL';
select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>b, c=>q';
-- @>
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>NULL';
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>NULL, c=>NULL';
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>NULL, g=>NULL';
select 'a=>b, b=>1, c=>NULL'::hstore @> 'g=>NULL';
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>c';
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b';
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b, c=>NULL';
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b, c=>q';
CREATE TABLE testhstore (h hstore);
\copy testhstore from 'data/hstore.data'
select count(*) from testhstore where h @ 'wait=>NULL';
select count(*) from testhstore where h @ 'wait=>CC';
select count(*) from testhstore where h @ 'wait=>CC, public=>t';
select count(*) from testhstore where h @> 'wait=>NULL';
select count(*) from testhstore where h @> 'wait=>CC';
select count(*) from testhstore where h @> 'wait=>CC, public=>t';
create index hidx on testhstore using gist(h);
set enable_seqscan=off;
select count(*) from testhstore where h @ 'wait=>NULL';
select count(*) from testhstore where h @ 'wait=>CC';
select count(*) from testhstore where h @ 'wait=>CC, public=>t';
select count(*) from testhstore where h @> 'wait=>NULL';
select count(*) from testhstore where h @> 'wait=>CC';
select count(*) from testhstore where h @> 'wait=>CC, public=>t';
select count(*) from (select (each(h)).key from testhstore) as wow ;
select key, count(*) from (select (each(h)).key from testhstore) as wow group by key order by count desc, key;

View File

@ -70,10 +70,10 @@ test=# select intset(1);
OPERATIONS:
int[] && int[] - overlap - returns TRUE if arrays has at least one common elements.
int[] @ int[] - contains - returns TRUE if left array contains right array
int[] ~ int[] - contained - returns TRUE if left array is contained in right array
# int[] - return the number of elements in array
int[] && int[] - overlap - returns TRUE if arrays have at least one common element
int[] @> int[] - contains - returns TRUE if left array contains right array
int[] <@ int[] - contained - returns TRUE if left array is contained in right array
# int[] - returns the number of elements in array
int[] + int - push element to array ( add to end of array)
int[] + int[] - merge of arrays (right array added to the end of left one)
int[] - int - remove entries matched by right argument from array
@ -81,8 +81,14 @@ OPERATIONS:
int[] | int - returns intarray - union of arguments
int[] | int[] - returns intarray as a union of two arrays
int[] & int[] - returns intersection of arrays
int[] @@ query_int - returns TRUE if array satisfies query (like '1&(2|3)')
query_int ~~ int[] - -/-
int[] @@ query_int - returns TRUE if array satisfies query (like '1&(2|3)')
query_int ~~ int[] - returns TRUE if array satisfies query (commutator of @@)
(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!)
CHANGES:
@ -128,9 +134,9 @@ CREATE INDEX message_rdtree_idx on message using gist ( sections gist__int_ops);
select message.mid from message where message.sections && '{1,2}';
-- select messages contains in sections 1 AND 2 - CONTAINS operator
select message.mid from message where message.sections @ '{1,2}';
select message.mid from message where message.sections @> '{1,2}';
-- the same, CONTAINED operator
select message.mid from message where '{1,2}' ~ message.sections;
select message.mid from message where '{1,2}' <@ message.sections;
BENCHMARK:

View File

@ -12,12 +12,12 @@ BEGIN;
CREATE FUNCTION bqarr_in(cstring)
RETURNS query_int
AS 'MODULE_PATHNAME'
LANGUAGE C RETURNS NULL ON NULL INPUT;
LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
CREATE FUNCTION bqarr_out(query_int)
RETURNS cstring
AS 'MODULE_PATHNAME'
LANGUAGE C RETURNS NULL ON NULL INPUT;
LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
CREATE TYPE query_int (
INTERNALLENGTH = -1,
@ -29,20 +29,20 @@ CREATE TYPE query_int (
CREATE FUNCTION querytree(query_int)
RETURNS text
AS 'MODULE_PATHNAME'
LANGUAGE C RETURNS NULL ON NULL INPUT;
LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
CREATE FUNCTION boolop(_int4, query_int)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C RETURNS NULL ON NULL INPUT;
LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
COMMENT ON FUNCTION boolop(_int4, query_int) IS 'boolean operation with array';
CREATE FUNCTION rboolop(query_int, _int4)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C RETURNS NULL ON NULL INPUT;
LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
COMMENT ON FUNCTION rboolop(query_int, _int4) IS 'boolean operation with array';
@ -74,35 +74,35 @@ CREATE OPERATOR ~~ (
CREATE FUNCTION _int_contains(_int4, _int4)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C RETURNS NULL ON NULL INPUT;
LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
COMMENT ON FUNCTION _int_contains(_int4, _int4) IS 'contains';
CREATE FUNCTION _int_contained(_int4, _int4)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C RETURNS NULL ON NULL INPUT;
LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
COMMENT ON FUNCTION _int_contained(_int4, _int4) IS 'contained in';
CREATE FUNCTION _int_overlap(_int4, _int4)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C RETURNS NULL ON NULL INPUT;
LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
COMMENT ON FUNCTION _int_overlap(_int4, _int4) IS 'overlaps';
CREATE FUNCTION _int_same(_int4, _int4)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C RETURNS NULL ON NULL INPUT;
LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
COMMENT ON FUNCTION _int_same(_int4, _int4) IS 'same as';
CREATE FUNCTION _int_different(_int4, _int4)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C RETURNS NULL ON NULL INPUT;
LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
COMMENT ON FUNCTION _int_different(_int4, _int4) IS 'different';
@ -111,12 +111,12 @@ COMMENT ON FUNCTION _int_different(_int4, _int4) IS 'different';
CREATE FUNCTION _int_union(_int4, _int4)
RETURNS _int4
AS 'MODULE_PATHNAME'
LANGUAGE C RETURNS NULL ON NULL INPUT;
LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
CREATE FUNCTION _int_inter(_int4, _int4)
RETURNS _int4
AS 'MODULE_PATHNAME'
LANGUAGE C RETURNS NULL ON NULL INPUT;
LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
--
-- OPERATORS
@ -153,6 +153,25 @@ CREATE OPERATOR && (
-- JOIN = neqjoinsel
--);
CREATE OPERATOR @> (
LEFTARG = _int4,
RIGHTARG = _int4,
PROCEDURE = _int_contains,
COMMUTATOR = '<@',
RESTRICT = contsel,
JOIN = contjoinsel
);
CREATE OPERATOR <@ (
LEFTARG = _int4,
RIGHTARG = _int4,
PROCEDURE = _int_contained,
COMMUTATOR = '@>',
RESTRICT = contsel,
JOIN = contjoinsel
);
-- obsolete:
CREATE OPERATOR @ (
LEFTARG = _int4,
RIGHTARG = _int4,
@ -347,8 +366,10 @@ CREATE OPERATOR CLASS gist__int_ops
DEFAULT FOR TYPE _int4 USING gist AS
OPERATOR 3 &&,
OPERATOR 6 = (anyarray, anyarray) RECHECK,
OPERATOR 7 @,
OPERATOR 8 ~,
OPERATOR 7 @>,
OPERATOR 8 <@,
OPERATOR 13 @,
OPERATOR 14 ~,
OPERATOR 20 @@ (_int4, query_int),
FUNCTION 1 g_int_consistent (internal, _int4, int4),
FUNCTION 2 g_int_union (internal, internal),
@ -367,12 +388,12 @@ DEFAULT FOR TYPE _int4 USING gist AS
CREATE FUNCTION _intbig_in(cstring)
RETURNS intbig_gkey
AS 'MODULE_PATHNAME'
LANGUAGE C RETURNS NULL ON NULL INPUT;
LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
CREATE FUNCTION _intbig_out(intbig_gkey)
RETURNS cstring
AS 'MODULE_PATHNAME'
LANGUAGE C RETURNS NULL ON NULL INPUT;
LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
CREATE TYPE intbig_gkey (
INTERNALLENGTH = -1,
@ -422,8 +443,10 @@ FOR TYPE _int4 USING gist
AS
OPERATOR 3 && RECHECK,
OPERATOR 6 = (anyarray, anyarray) RECHECK,
OPERATOR 7 @ RECHECK,
OPERATOR 8 ~ RECHECK,
OPERATOR 7 @> RECHECK,
OPERATOR 8 <@ RECHECK,
OPERATOR 13 @ RECHECK,
OPERATOR 14 ~ RECHECK,
OPERATOR 20 @@ (_int4, query_int) RECHECK,
FUNCTION 1 g_intbig_consistent (internal, internal, int4),
FUNCTION 2 g_intbig_union (internal, internal),
@ -455,8 +478,10 @@ DEFAULT FOR TYPE _int4 USING gin
AS
OPERATOR 3 &&,
OPERATOR 6 = (anyarray, anyarray) RECHECK,
OPERATOR 7 @,
OPERATOR 8 ~ RECHECK,
OPERATOR 7 @>,
OPERATOR 8 <@ RECHECK,
OPERATOR 13 @,
OPERATOR 14 ~ RECHECK,
OPERATOR 20 @@ (_int4, query_int),
FUNCTION 1 btint4cmp (int4, int4),
FUNCTION 2 ginarrayextract (anyarray, internal),

View File

@ -68,12 +68,14 @@ ginint4_consistent(PG_FUNCTION_ARGS) {
switch( strategy ) {
case RTOverlapStrategyNumber:
case RTContainedByStrategyNumber:
case RTOldContainedByStrategyNumber:
/* at least one element in check[] is true, so result = true */
res = TRUE;
break;
case RTSameStrategyNumber:
case RTContainsStrategyNumber:
case RTOldContainsStrategyNumber:
res = TRUE;
do {
ArrayType *query = PG_GETARG_ARRAYTYPE_P(2);

View File

@ -72,10 +72,12 @@ g_int_consistent(PG_FUNCTION_ARGS)
query);
break;
case RTContainsStrategyNumber:
case RTOldContainsStrategyNumber:
retval = inner_int_contains((ArrayType *) DatumGetPointer(entry->key),
query);
break;
case RTContainedByStrategyNumber:
case RTOldContainedByStrategyNumber:
if (GIST_LEAF(entry))
retval = inner_int_contains(query,
(ArrayType *) DatumGetPointer(entry->key));

View File

@ -560,9 +560,11 @@ g_intbig_consistent(PG_FUNCTION_ARGS)
retval = _intbig_contains((GISTTYPE *) DatumGetPointer(entry->key), query);
break;
case RTContainsStrategyNumber:
case RTOldContainsStrategyNumber:
retval = _intbig_contains((GISTTYPE *) DatumGetPointer(entry->key), query);
break;
case RTContainedByStrategyNumber:
case RTOldContainedByStrategyNumber:
if (GIST_LEAF(entry))
{
int i,

View File

@ -2,13 +2,9 @@
-- first, define the datatype. Turn off echoing so that expected file
-- does not depend on contents of _int.sql.
--
SET client_min_messages = warning;
\set ECHO none
psql:_int.sql:15: NOTICE: type "query_int" is not yet defined
DETAIL: Creating a shell type definition.
psql:_int.sql:20: NOTICE: argument type query_int is only a shell
psql:_int.sql:370: NOTICE: type "intbig_gkey" is not yet defined
DETAIL: Creating a shell type definition.
psql:_int.sql:375: NOTICE: argument type intbig_gkey is only a shell
RESET client_min_messages;
SELECT intset(1234);
intset
--------
@ -384,7 +380,7 @@ SELECT count(*) from test__int WHERE a @@ '23|50';
403
(1 row)
SELECT count(*) from test__int WHERE a @ '{23,50}';
SELECT count(*) from test__int WHERE a @> '{23,50}';
count
-------
12
@ -396,7 +392,7 @@ SELECT count(*) from test__int WHERE a @@ '23&50';
12
(1 row)
SELECT count(*) from test__int WHERE a @ '{20,23}';
SELECT count(*) from test__int WHERE a @> '{20,23}';
count
-------
12
@ -408,7 +404,7 @@ SELECT count(*) from test__int WHERE a @@ '50&68';
9
(1 row)
SELECT count(*) from test__int WHERE a @ '{20,23}' or a @ '{50,68}';
SELECT count(*) from test__int WHERE a @> '{20,23}' or a @> '{50,68}';
count
-------
21
@ -433,7 +429,7 @@ SELECT count(*) from test__int WHERE a @@ '23|50';
403
(1 row)
SELECT count(*) from test__int WHERE a @ '{23,50}';
SELECT count(*) from test__int WHERE a @> '{23,50}';
count
-------
12
@ -445,7 +441,7 @@ SELECT count(*) from test__int WHERE a @@ '23&50';
12
(1 row)
SELECT count(*) from test__int WHERE a @ '{20,23}';
SELECT count(*) from test__int WHERE a @> '{20,23}';
count
-------
12
@ -457,7 +453,7 @@ SELECT count(*) from test__int WHERE a @@ '50&68';
9
(1 row)
SELECT count(*) from test__int WHERE a @ '{20,23}' or a @ '{50,68}';
SELECT count(*) from test__int WHERE a @> '{20,23}' or a @> '{50,68}';
count
-------
21
@ -483,7 +479,7 @@ SELECT count(*) from test__int WHERE a @@ '23|50';
403
(1 row)
SELECT count(*) from test__int WHERE a @ '{23,50}';
SELECT count(*) from test__int WHERE a @> '{23,50}';
count
-------
12
@ -495,7 +491,7 @@ SELECT count(*) from test__int WHERE a @@ '23&50';
12
(1 row)
SELECT count(*) from test__int WHERE a @ '{20,23}';
SELECT count(*) from test__int WHERE a @> '{20,23}';
count
-------
12
@ -507,7 +503,7 @@ SELECT count(*) from test__int WHERE a @@ '50&68';
9
(1 row)
SELECT count(*) from test__int WHERE a @ '{20,23}' or a @ '{50,68}';
SELECT count(*) from test__int WHERE a @> '{20,23}' or a @> '{50,68}';
count
-------
21
@ -533,7 +529,7 @@ SELECT count(*) from test__int WHERE a @@ '23|50';
403
(1 row)
SELECT count(*) from test__int WHERE a @ '{23,50}';
SELECT count(*) from test__int WHERE a @> '{23,50}';
count
-------
12
@ -545,7 +541,7 @@ SELECT count(*) from test__int WHERE a @@ '23&50';
12
(1 row)
SELECT count(*) from test__int WHERE a @ '{20,23}';
SELECT count(*) from test__int WHERE a @> '{20,23}';
count
-------
12
@ -557,7 +553,7 @@ SELECT count(*) from test__int WHERE a @@ '50&68';
9
(1 row)
SELECT count(*) from test__int WHERE a @ '{20,23}' or a @ '{50,68}';
SELECT count(*) from test__int WHERE a @> '{20,23}' or a @> '{50,68}';
count
-------
21

View File

@ -2,9 +2,11 @@
-- first, define the datatype. Turn off echoing so that expected file
-- does not depend on contents of _int.sql.
--
SET client_min_messages = warning;
\set ECHO none
\i _int.sql
\set ECHO all
RESET client_min_messages;
SELECT intset(1234);
SELECT icount('{1234234,234234}');
@ -78,22 +80,22 @@ CREATE TABLE test__int( a int[] );
SELECT count(*) from test__int WHERE a && '{23,50}';
SELECT count(*) from test__int WHERE a @@ '23|50';
SELECT count(*) from test__int WHERE a @ '{23,50}';
SELECT count(*) from test__int WHERE a @> '{23,50}';
SELECT count(*) from test__int WHERE a @@ '23&50';
SELECT count(*) from test__int WHERE a @ '{20,23}';
SELECT count(*) from test__int WHERE a @> '{20,23}';
SELECT count(*) from test__int WHERE a @@ '50&68';
SELECT count(*) from test__int WHERE a @ '{20,23}' or a @ '{50,68}';
SELECT count(*) from test__int WHERE a @> '{20,23}' or a @> '{50,68}';
SELECT count(*) from test__int WHERE a @@ '(20&23)|(50&68)';
CREATE INDEX text_idx on test__int using gist ( a gist__int_ops );
SELECT count(*) from test__int WHERE a && '{23,50}';
SELECT count(*) from test__int WHERE a @@ '23|50';
SELECT count(*) from test__int WHERE a @ '{23,50}';
SELECT count(*) from test__int WHERE a @> '{23,50}';
SELECT count(*) from test__int WHERE a @@ '23&50';
SELECT count(*) from test__int WHERE a @ '{20,23}';
SELECT count(*) from test__int WHERE a @> '{20,23}';
SELECT count(*) from test__int WHERE a @@ '50&68';
SELECT count(*) from test__int WHERE a @ '{20,23}' or a @ '{50,68}';
SELECT count(*) from test__int WHERE a @> '{20,23}' or a @> '{50,68}';
SELECT count(*) from test__int WHERE a @@ '(20&23)|(50&68)';
DROP INDEX text_idx;
@ -101,11 +103,11 @@ CREATE INDEX text_idx on test__int using gist ( a gist__intbig_ops );
SELECT count(*) from test__int WHERE a && '{23,50}';
SELECT count(*) from test__int WHERE a @@ '23|50';
SELECT count(*) from test__int WHERE a @ '{23,50}';
SELECT count(*) from test__int WHERE a @> '{23,50}';
SELECT count(*) from test__int WHERE a @@ '23&50';
SELECT count(*) from test__int WHERE a @ '{20,23}';
SELECT count(*) from test__int WHERE a @> '{20,23}';
SELECT count(*) from test__int WHERE a @@ '50&68';
SELECT count(*) from test__int WHERE a @ '{20,23}' or a @ '{50,68}';
SELECT count(*) from test__int WHERE a @> '{20,23}' or a @> '{50,68}';
SELECT count(*) from test__int WHERE a @@ '(20&23)|(50&68)';
DROP INDEX text_idx;
@ -113,9 +115,9 @@ CREATE INDEX text_idx on test__int using gin ( a );
SELECT count(*) from test__int WHERE a && '{23,50}';
SELECT count(*) from test__int WHERE a @@ '23|50';
SELECT count(*) from test__int WHERE a @ '{23,50}';
SELECT count(*) from test__int WHERE a @> '{23,50}';
SELECT count(*) from test__int WHERE a @@ '23&50';
SELECT count(*) from test__int WHERE a @ '{20,23}';
SELECT count(*) from test__int WHERE a @> '{20,23}';
SELECT count(*) from test__int WHERE a @@ '50&68';
SELECT count(*) from test__int WHERE a @ '{20,23}' or a @ '{50,68}';
SELECT count(*) from test__int WHERE a @> '{20,23}' or a @> '{50,68}';
SELECT count(*) from test__int WHERE a @@ '(20&23)|(50&68)';

View File

@ -1,5 +1,11 @@
SET search_path = public;
DROP OPERATOR CLASS gin__int_ops USING gin;
DROP FUNCTION ginint4_queryextract(internal, internal, int2);
DROP FUNCTION ginint4_consistent(internal, int2, internal);
DROP OPERATOR CLASS gist__intbig_ops USING gist;
DROP FUNCTION g_intbig_same(internal, internal, internal);
@ -82,6 +88,10 @@ DROP FUNCTION icount(_int4);
DROP FUNCTION intset(int4);
DROP OPERATOR <@ (_int4, _int4);
DROP OPERATOR @> (_int4, _int4);
DROP OPERATOR ~ (_int4, _int4);
DROP OPERATOR @ (_int4, _int4);

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);

File diff suppressed because it is too large Load Diff

View File

@ -184,11 +184,28 @@ gtsq_consistent(PG_FUNCTION_ARGS)
QUERYTYPE *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
TPQTGist sq = makesign(query);
bool retval;
if (GIST_LEAF(entry))
PG_RETURN_BOOL(((*key) & sq) == ((strategy == 1) ? sq : *key));
else
PG_RETURN_BOOL((*key) & sq);
switch (strategy)
{
case RTContainsStrategyNumber:
case RTOldContainsStrategyNumber:
if (GIST_LEAF(entry))
retval = (*key & sq) == sq;
else
retval = (*key & sq) != 0;
break;
case RTContainedByStrategyNumber:
case RTOldContainedByStrategyNumber:
if (GIST_LEAF(entry))
retval = (*key & sq) == *key;
else
retval = (*key & sq) != 0;
break;
default:
retval = FALSE;
}
PG_RETURN_BOOL(retval);
}
Datum

View File

@ -1,10 +1,12 @@
--
-- first, define the datatype. Turn off echoing so that expected file
-- does not depend on contents of seg.sql.
-- does not depend on contents of tsearch2.sql.
--
SET client_min_messages = warning;
\set ECHO none
\i tsearch2.sql
\set ECHO all
RESET client_min_messages;
--tsvector
SELECT '1'::tsvector;
@ -119,30 +121,30 @@ select rewrite( ARRAY['moscow & hotel', keyword, sample] ) from test_tsquery;
select rewrite( ARRAY['bar & new & qq & foo & york', keyword, sample] ) from test_tsquery;
select keyword from test_tsquery where keyword @ 'new';
select keyword from test_tsquery where keyword @ 'moscow';
select keyword from test_tsquery where keyword ~ 'new';
select keyword from test_tsquery where keyword ~ 'moscow';
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow') as query where keyword ~ query;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow & hotel') as query where keyword ~ query;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'bar & new & qq & foo & york') as query where keyword ~ query;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow') as query where query @ keyword;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow & hotel') as query where query @ keyword;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'bar & new & qq & foo & york') as query where query @ keyword;
select keyword from test_tsquery where keyword @> 'new';
select keyword from test_tsquery where keyword @> 'moscow';
select keyword from test_tsquery where keyword <@ 'new';
select keyword from test_tsquery where keyword <@ 'moscow';
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow') as query where keyword <@ query;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow & hotel') as query where keyword <@ query;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'bar & new & qq & foo & york') as query where keyword <@ query;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow') as query where query @> keyword;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow & hotel') as query where query @> keyword;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'bar & new & qq & foo & york') as query where query @> keyword;
create index qq on test_tsquery using gist (keyword gist_tp_tsquery_ops);
set enable_seqscan='off';
select keyword from test_tsquery where keyword @ 'new';
select keyword from test_tsquery where keyword @ 'moscow';
select keyword from test_tsquery where keyword ~ 'new';
select keyword from test_tsquery where keyword ~ 'moscow';
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow') as query where keyword ~ query;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow & hotel') as query where keyword ~ query;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'bar & new & qq & foo & york') as query where keyword ~ query;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow') as query where query @ keyword;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow & hotel') as query where query @ keyword;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'bar & new & qq & foo & york') as query where query @ keyword;
select keyword from test_tsquery where keyword @> 'new';
select keyword from test_tsquery where keyword @> 'moscow';
select keyword from test_tsquery where keyword <@ 'new';
select keyword from test_tsquery where keyword <@ 'moscow';
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow') as query where keyword <@ query;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow & hotel') as query where keyword <@ query;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'bar & new & qq & foo & york') as query where keyword <@ query;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow') as query where query @> keyword;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow & hotel') as query where query @> keyword;
select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'bar & new & qq & foo & york') as query where query @> keyword;
set enable_seqscan='on';

View File

@ -1080,6 +1080,25 @@ CREATE OR REPLACE FUNCTION tsq_mcontained(tsquery, tsquery)
LANGUAGE C
RETURNS NULL ON NULL INPUT IMMUTABLE;
CREATE OPERATOR @> (
LEFTARG = tsquery,
RIGHTARG = tsquery,
PROCEDURE = tsq_mcontains,
COMMUTATOR = '<@',
RESTRICT = contsel,
JOIN = contjoinsel
);
CREATE OPERATOR <@ (
LEFTARG = tsquery,
RIGHTARG = tsquery,
PROCEDURE = tsq_mcontained,
COMMUTATOR = '@>',
RESTRICT = contsel,
JOIN = contjoinsel
);
-- obsolete:
CREATE OPERATOR @ (
LEFTARG = tsquery,
RIGHTARG = tsquery,
@ -1154,8 +1173,10 @@ LANGUAGE C;
CREATE OPERATOR CLASS gist_tp_tsquery_ops
DEFAULT FOR TYPE tsquery USING gist
AS
OPERATOR 1 @ (tsquery, tsquery) RECHECK,
OPERATOR 2 ~ (tsquery, tsquery) RECHECK,
OPERATOR 7 @> (tsquery, tsquery) RECHECK,
OPERATOR 8 <@ (tsquery, tsquery) RECHECK,
OPERATOR 13 @ (tsquery, tsquery) RECHECK,
OPERATOR 14 ~ (tsquery, tsquery) RECHECK,
FUNCTION 1 gtsq_consistent (gtsq, internal, int4),
FUNCTION 2 gtsq_union (bytea, internal),
FUNCTION 3 gtsq_compress (internal),

View File

@ -5,6 +5,8 @@ BEGIN;
--in tsearch2.sql
DROP OPERATOR CLASS gin_tsvector_ops USING gin CASCADE;
DROP OPERATOR CLASS gist_tsvector_ops USING gist CASCADE;
@ -27,7 +29,7 @@ DROP TYPE gtsvector CASCADE;
--DROP TYPE tsstat CASCADE;
DROP TYPE statinfo CASCADE;
DROP TYPE tsdebug CASCADE;
DROP TYPE gtsq CASCADE;
DROP FUNCTION lexize(oid, text) ;
DROP FUNCTION lexize(text, text);
@ -38,11 +40,12 @@ DROP FUNCTION dex_init(internal);
DROP FUNCTION dex_lexize(internal,internal,int4);
DROP FUNCTION snb_en_init(internal);
DROP FUNCTION snb_lexize(internal,internal,int4);
DROP FUNCTION snb_ru_init(internal);
DROP FUNCTION snb_ru_init_koi8(internal);
DROP FUNCTION snb_ru_init_utf8(internal);
DROP FUNCTION spell_init(internal);
DROP FUNCTION spell_lexize(internal,internal,int4);
DROP FUNCTION thesaurus_init(internal);
DROP FUNCTION thesaurus_lexize(internal,internal,int4);
DROP FUNCTION thesaurus_lexize(internal,internal,int4,internal);
DROP FUNCTION syn_init(internal);
DROP FUNCTION syn_lexize(internal,internal,int4);
DROP FUNCTION set_curprs(int);
@ -60,6 +63,11 @@ DROP FUNCTION gtsvector_decompress(internal);
DROP FUNCTION gtsvector_penalty(internal,internal,internal);
DROP FUNCTION gtsvector_picksplit(internal, internal);
DROP FUNCTION gtsvector_union(internal, internal);
DROP FUNCTION gtsq_compress(internal);
DROP FUNCTION gtsq_decompress(internal);
DROP FUNCTION gtsq_penalty(internal,internal,internal);
DROP FUNCTION gtsq_picksplit(internal, internal);
DROP FUNCTION gtsq_union(bytea, internal);
DROP FUNCTION reset_tsearch();
DROP FUNCTION tsearch2() CASCADE;
DROP FUNCTION _get_parser_from_curcfg();

View File

@ -1,5 +1,5 @@
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/create_opclass.sgml,v 1.14 2006/01/13 18:10:25 tgl Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/create_opclass.sgml,v 1.15 2006/09/10 17:36:52 tgl Exp $
PostgreSQL documentation
-->
@ -238,8 +238,8 @@ CREATE OPERATOR CLASS gist__int_ops
DEFAULT FOR TYPE _int4 USING gist AS
OPERATOR 3 &&,
OPERATOR 6 = RECHECK,
OPERATOR 7 @,
OPERATOR 8 ~,
OPERATOR 7 @>,
OPERATOR 8 <@,
OPERATOR 20 @@ (_int4, query_int),
FUNCTION 1 g_int_consistent (internal, _int4, int4),
FUNCTION 2 g_int_union (bytea, internal),