2000-12-12 04:39:15 +08:00
|
|
|
-- Create the user-defined type for N-dimensional boxes
|
|
|
|
--
|
2002-09-12 08:26:00 +08:00
|
|
|
BEGIN;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
2002-07-31 01:34:37 +08:00
|
|
|
-- Adjust this setting to control where the objects get created.
|
|
|
|
SET search_path = public;
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_in(cstring)
|
2002-08-22 08:01:51 +08:00
|
|
|
RETURNS cube
|
2000-12-12 04:39:15 +08:00
|
|
|
AS 'MODULE_PATHNAME'
|
2002-08-30 07:03:58 +08:00
|
|
|
LANGUAGE 'c'IMMUTABLE STRICT;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_out(cube)
|
2002-08-22 08:01:51 +08:00
|
|
|
RETURNS cstring
|
2000-12-12 04:39:15 +08:00
|
|
|
AS 'MODULE_PATHNAME'
|
2002-08-30 07:03:58 +08:00
|
|
|
LANGUAGE 'c'IMMUTABLE STRICT;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
|
|
|
CREATE TYPE cube (
|
|
|
|
internallength = variable,
|
|
|
|
input = cube_in,
|
|
|
|
output = cube_out
|
|
|
|
);
|
|
|
|
|
|
|
|
COMMENT ON TYPE cube IS
|
|
|
|
'multi-dimensional cube ''(FLOAT-1, FLOAT-2, ..., FLOAT-N), (FLOAT-1, FLOAT-2, ..., FLOAT-N)''';
|
|
|
|
|
2002-08-30 07:03:58 +08:00
|
|
|
-- Convert from text to cube
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube(text) RETURNS cube
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE 'c' IMMUTABLE STRICT;
|
|
|
|
|
|
|
|
COMMENT ON FUNCTION cube(text) IS
|
|
|
|
'convert text to cube';
|
|
|
|
|
2000-12-12 04:39:15 +08:00
|
|
|
--
|
|
|
|
-- External C-functions for R-tree methods
|
|
|
|
--
|
|
|
|
|
|
|
|
-- Left/Right methods
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_over_left(cube, cube) RETURNS bool
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
|
|
|
COMMENT ON FUNCTION cube_over_left(cube, cube) IS
|
|
|
|
'is over and left of (NOT IMPLEMENTED)';
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_over_right(cube, cube) RETURNS bool
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
|
|
|
COMMENT ON FUNCTION cube_over_right(cube, cube) IS
|
|
|
|
'is over and right of (NOT IMPLEMENTED)';
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_left(cube, cube) RETURNS bool
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
|
|
|
COMMENT ON FUNCTION cube_left(cube, cube) IS
|
|
|
|
'is left of (NOT IMPLEMENTED)';
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_right(cube, cube) RETURNS bool
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
|
|
|
COMMENT ON FUNCTION cube_right(cube, cube) IS
|
|
|
|
'is right of (NOT IMPLEMENTED)';
|
|
|
|
|
|
|
|
|
|
|
|
-- Comparison methods
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_lt(cube, cube) RETURNS bool
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
|
|
|
COMMENT ON FUNCTION cube_lt(cube, cube) IS
|
|
|
|
'lower than';
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_gt(cube, cube) RETURNS bool
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
|
|
|
COMMENT ON FUNCTION cube_gt(cube, cube) IS
|
|
|
|
'greater than';
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_contains(cube, cube) RETURNS bool
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
|
|
|
COMMENT ON FUNCTION cube_contains(cube, cube) IS
|
|
|
|
'contains';
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_contained(cube, cube) RETURNS bool
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
|
|
|
COMMENT ON FUNCTION cube_contained(cube, cube) IS
|
|
|
|
'contained in';
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_overlap(cube, cube) RETURNS bool
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
|
|
|
COMMENT ON FUNCTION cube_overlap(cube, cube) IS
|
|
|
|
'overlaps';
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_same(cube, cube) RETURNS bool
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
|
|
|
COMMENT ON FUNCTION cube_same(cube, cube) IS
|
|
|
|
'same as';
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_different(cube, cube) RETURNS bool
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
|
|
|
COMMENT ON FUNCTION cube_different(cube, cube) IS
|
|
|
|
'different';
|
|
|
|
|
|
|
|
-- support routines for indexing
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_union(cube, cube) RETURNS cube
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_inter(cube, cube) RETURNS cube
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_size(cube) RETURNS float8
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
-- Misc N-dimensional functions
|
|
|
|
|
|
|
|
-- proximity routines
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_distance(cube, cube) RETURNS float8
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
|
|
|
|
|
|
|
-- Extracting elements functions
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_dim(cube) RETURNS int4
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_ll_coord(cube, int4) RETURNS float8
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_ur_coord(cube, int4) RETURNS float8
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
|
|
|
|
|
|
|
-- Test if cube is also a point
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_is_point(cube) RETURNS bool
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
|
|
|
|
|
|
|
-- Increasing the size of a cube by a radius in at least n dimensions
|
2000-12-12 04:39:15 +08:00
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cube_enlarge(cube, float8, int4) RETURNS cube
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
|
|
|
--
|
|
|
|
-- OPERATORS
|
|
|
|
--
|
|
|
|
|
|
|
|
CREATE OPERATOR < (
|
|
|
|
LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_lt,
|
|
|
|
COMMUTATOR = '>',
|
|
|
|
RESTRICT = scalarltsel, JOIN = scalarltjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE OPERATOR > (
|
|
|
|
LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_gt,
|
|
|
|
COMMUTATOR = '<',
|
|
|
|
RESTRICT = scalargtsel, JOIN = scalargtjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE OPERATOR << (
|
|
|
|
LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_left,
|
|
|
|
COMMUTATOR = '>>',
|
|
|
|
RESTRICT = positionsel, JOIN = positionjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE OPERATOR &< (
|
|
|
|
LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_over_left,
|
|
|
|
COMMUTATOR = '&>',
|
|
|
|
RESTRICT = positionsel, JOIN = positionjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE OPERATOR && (
|
|
|
|
LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_overlap,
|
|
|
|
COMMUTATOR = '&&',
|
|
|
|
RESTRICT = positionsel, JOIN = positionjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE OPERATOR &> (
|
|
|
|
LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_over_right,
|
|
|
|
COMMUTATOR = '&<',
|
|
|
|
RESTRICT = positionsel, JOIN = positionjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE OPERATOR >> (
|
|
|
|
LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_right,
|
|
|
|
COMMUTATOR = '<<',
|
|
|
|
RESTRICT = positionsel, JOIN = positionjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE OPERATOR = (
|
|
|
|
LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_same,
|
|
|
|
COMMUTATOR = '=', NEGATOR = '<>',
|
|
|
|
RESTRICT = eqsel, JOIN = eqjoinsel,
|
|
|
|
SORT1 = '<', SORT2 = '<'
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE OPERATOR <> (
|
|
|
|
LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_different,
|
|
|
|
COMMUTATOR = '<>', NEGATOR = '=',
|
|
|
|
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
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
-- define the GiST support methods
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION g_cube_consistent(internal,cube,int4) RETURNS bool
|
2000-12-12 04:39:15 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c';
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION g_cube_compress(internal) RETURNS internal
|
2000-12-12 04:39:15 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c';
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION g_cube_decompress(internal) RETURNS internal
|
2000-12-12 04:39:15 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c';
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION g_cube_penalty(internal,internal,internal) RETURNS internal
|
2002-08-30 07:03:58 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' STRICT;
|
2000-12-12 04:39:15 +08:00
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION g_cube_picksplit(internal, internal) RETURNS internal
|
2000-12-12 04:39:15 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c';
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION g_cube_union(bytea, internal) RETURNS cube
|
2000-12-12 04:39:15 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c';
|
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
CREATE OR REPLACE FUNCTION g_cube_same(cube, cube, internal) RETURNS internal
|
2000-12-12 04:39:15 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c';
|
|
|
|
|
|
|
|
|
2002-07-31 01:34:37 +08:00
|
|
|
-- Create the operator class for indexing
|
|
|
|
|
|
|
|
CREATE OPERATOR CLASS gist_cube_ops
|
|
|
|
DEFAULT FOR TYPE cube USING gist AS
|
|
|
|
OPERATOR 1 << ,
|
|
|
|
OPERATOR 2 &< ,
|
|
|
|
OPERATOR 3 && ,
|
|
|
|
OPERATOR 4 &> ,
|
|
|
|
OPERATOR 5 >> ,
|
|
|
|
OPERATOR 6 = ,
|
|
|
|
OPERATOR 7 @ ,
|
|
|
|
OPERATOR 8 ~ ,
|
2002-08-22 08:01:51 +08:00
|
|
|
FUNCTION 1 g_cube_consistent (internal, cube, int4),
|
|
|
|
FUNCTION 2 g_cube_union (bytea, internal),
|
|
|
|
FUNCTION 3 g_cube_compress (internal),
|
|
|
|
FUNCTION 4 g_cube_decompress (internal),
|
|
|
|
FUNCTION 5 g_cube_penalty (internal, internal, internal),
|
|
|
|
FUNCTION 6 g_cube_picksplit (internal, internal),
|
|
|
|
FUNCTION 7 g_cube_same (cube, cube, internal);
|
2002-07-31 01:34:37 +08:00
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
--
|
|
|
|
-- By default the externally visible functions are made executable by
|
|
|
|
-- anyone. To restrict their access comment out the following grant commands.
|
|
|
|
--
|
2000-12-12 04:39:15 +08:00
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
GRANT EXECUTE ON FUNCTION cube(text) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_over_left(cube, cube) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_over_right(cube, cube) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_left(cube, cube) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_right(cube, cube) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_lt(cube, cube) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_gt(cube, cube) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_contains(cube, cube) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_contained(cube, cube) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_overlap(cube, cube) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_same(cube, cube) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_different(cube, cube) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_union(cube, cube) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_inter(cube, cube) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_size(cube) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_distance(cube, cube) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_dim(cube) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_ll_coord(cube, int4) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_ur_coord(cube, int4) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_is_point(cube) TO PUBLIC;
|
|
|
|
GRANT EXECUTE ON FUNCTION cube_enlarge(cube, float8, int4) TO PUBLIC;
|
|
|
|
|
|
|
|
COMMIT;
|