Mark contrib's GiST and GIN opclass support functions as STRICT, for safety.
[PostgreSQL.git] / contrib / seg / seg.sql.in
blobb891d01769f5184b6a712276e24c2f9166b1865b
1 /* $PostgreSQL$ */
3 -- Adjust this setting to control where the objects get created.
4 SET search_path = public;
6 -- Create the user-defined type for 1-D floating point intervals (seg)
7 --
9 CREATE OR REPLACE FUNCTION seg_in(cstring)
10 RETURNS seg
11 AS 'MODULE_PATHNAME'
12 LANGUAGE C STRICT IMMUTABLE;
14 CREATE OR REPLACE FUNCTION seg_out(seg)
15 RETURNS cstring
16 AS 'MODULE_PATHNAME'
17 LANGUAGE C STRICT IMMUTABLE;
19 CREATE TYPE seg (
20 INTERNALLENGTH = 12,
21 INPUT = seg_in,
22 OUTPUT = seg_out
25 COMMENT ON TYPE seg IS
26 'floating point interval ''FLOAT .. FLOAT'', ''.. FLOAT'', ''FLOAT ..'' or ''FLOAT''';
29 -- External C-functions for R-tree methods
32 -- Left/Right methods
34 CREATE OR REPLACE FUNCTION seg_over_left(seg, seg)
35 RETURNS bool
36 AS 'MODULE_PATHNAME'
37 LANGUAGE C STRICT IMMUTABLE;
39 COMMENT ON FUNCTION seg_over_left(seg, seg) IS
40 'overlaps or is left of';
42 CREATE OR REPLACE FUNCTION seg_over_right(seg, seg)
43 RETURNS bool
44 AS 'MODULE_PATHNAME'
45 LANGUAGE C STRICT IMMUTABLE;
47 COMMENT ON FUNCTION seg_over_right(seg, seg) IS
48 'overlaps or is right of';
50 CREATE OR REPLACE FUNCTION seg_left(seg, seg)
51 RETURNS bool
52 AS 'MODULE_PATHNAME'
53 LANGUAGE C STRICT IMMUTABLE;
55 COMMENT ON FUNCTION seg_left(seg, seg) IS
56 'is left of';
58 CREATE OR REPLACE FUNCTION seg_right(seg, seg)
59 RETURNS bool
60 AS 'MODULE_PATHNAME'
61 LANGUAGE C STRICT IMMUTABLE;
63 COMMENT ON FUNCTION seg_right(seg, seg) IS
64 'is right of';
67 -- Scalar comparison methods
69 CREATE OR REPLACE FUNCTION seg_lt(seg, seg)
70 RETURNS bool
71 AS 'MODULE_PATHNAME'
72 LANGUAGE C STRICT IMMUTABLE;
74 COMMENT ON FUNCTION seg_lt(seg, seg) IS
75 'less than';
77 CREATE OR REPLACE FUNCTION seg_le(seg, seg)
78 RETURNS bool
79 AS 'MODULE_PATHNAME'
80 LANGUAGE C STRICT IMMUTABLE;
82 COMMENT ON FUNCTION seg_le(seg, seg) IS
83 'less than or equal';
85 CREATE OR REPLACE FUNCTION seg_gt(seg, seg)
86 RETURNS bool
87 AS 'MODULE_PATHNAME'
88 LANGUAGE C STRICT IMMUTABLE;
90 COMMENT ON FUNCTION seg_gt(seg, seg) IS
91 'greater than';
93 CREATE OR REPLACE FUNCTION seg_ge(seg, seg)
94 RETURNS bool
95 AS 'MODULE_PATHNAME'
96 LANGUAGE C STRICT IMMUTABLE;
98 COMMENT ON FUNCTION seg_ge(seg, seg) IS
99 'greater than or equal';
101 CREATE OR REPLACE FUNCTION seg_contains(seg, seg)
102 RETURNS bool
103 AS 'MODULE_PATHNAME'
104 LANGUAGE C STRICT IMMUTABLE;
106 COMMENT ON FUNCTION seg_contains(seg, seg) IS
107 'contains';
109 CREATE OR REPLACE FUNCTION seg_contained(seg, seg)
110 RETURNS bool
111 AS 'MODULE_PATHNAME'
112 LANGUAGE C STRICT IMMUTABLE;
114 COMMENT ON FUNCTION seg_contained(seg, seg) IS
115 'contained in';
117 CREATE OR REPLACE FUNCTION seg_overlap(seg, seg)
118 RETURNS bool
119 AS 'MODULE_PATHNAME'
120 LANGUAGE C STRICT IMMUTABLE;
122 COMMENT ON FUNCTION seg_overlap(seg, seg) IS
123 'overlaps';
125 CREATE OR REPLACE FUNCTION seg_same(seg, seg)
126 RETURNS bool
127 AS 'MODULE_PATHNAME'
128 LANGUAGE C STRICT IMMUTABLE;
130 COMMENT ON FUNCTION seg_same(seg, seg) IS
131 'same as';
133 CREATE OR REPLACE FUNCTION seg_different(seg, seg)
134 RETURNS bool
135 AS 'MODULE_PATHNAME'
136 LANGUAGE C STRICT IMMUTABLE;
138 COMMENT ON FUNCTION seg_different(seg, seg) IS
139 'different';
141 -- support routines for indexing
143 CREATE OR REPLACE FUNCTION seg_cmp(seg, seg)
144 RETURNS int4
145 AS 'MODULE_PATHNAME'
146 LANGUAGE C STRICT IMMUTABLE;
148 COMMENT ON FUNCTION seg_cmp(seg, seg) IS 'btree comparison function';
150 CREATE OR REPLACE FUNCTION seg_union(seg, seg)
151 RETURNS seg
152 AS 'MODULE_PATHNAME'
153 LANGUAGE C STRICT IMMUTABLE;
155 CREATE OR REPLACE FUNCTION seg_inter(seg, seg)
156 RETURNS seg
157 AS 'MODULE_PATHNAME'
158 LANGUAGE C STRICT IMMUTABLE;
160 CREATE OR REPLACE FUNCTION seg_size(seg)
161 RETURNS float4
162 AS 'MODULE_PATHNAME'
163 LANGUAGE C STRICT IMMUTABLE;
165 -- miscellaneous
167 CREATE OR REPLACE FUNCTION seg_center(seg)
168 RETURNS float4
169 AS 'MODULE_PATHNAME'
170 LANGUAGE C STRICT IMMUTABLE;
172 CREATE OR REPLACE FUNCTION seg_upper(seg)
173 RETURNS float4
174 AS 'MODULE_PATHNAME'
175 LANGUAGE C STRICT IMMUTABLE;
177 CREATE OR REPLACE FUNCTION seg_lower(seg)
178 RETURNS float4
179 AS 'MODULE_PATHNAME'
180 LANGUAGE C STRICT IMMUTABLE;
184 -- OPERATORS
187 CREATE OPERATOR < (
188 LEFTARG = seg,
189 RIGHTARG = seg,
190 PROCEDURE = seg_lt,
191 COMMUTATOR = '>',
192 NEGATOR = '>=',
193 RESTRICT = scalarltsel,
194 JOIN = scalarltjoinsel
197 CREATE OPERATOR <= (
198 LEFTARG = seg,
199 RIGHTARG = seg,
200 PROCEDURE = seg_le,
201 COMMUTATOR = '>=',
202 NEGATOR = '>',
203 RESTRICT = scalarltsel,
204 JOIN = scalarltjoinsel
207 CREATE OPERATOR > (
208 LEFTARG = seg,
209 RIGHTARG = seg,
210 PROCEDURE = seg_gt,
211 COMMUTATOR = '<',
212 NEGATOR = '<=',
213 RESTRICT = scalargtsel,
214 JOIN = scalargtjoinsel
217 CREATE OPERATOR >= (
218 LEFTARG = seg,
219 RIGHTARG = seg,
220 PROCEDURE = seg_ge,
221 COMMUTATOR = '<=',
222 NEGATOR = '<',
223 RESTRICT = scalargtsel,
224 JOIN = scalargtjoinsel
227 CREATE OPERATOR << (
228 LEFTARG = seg,
229 RIGHTARG = seg,
230 PROCEDURE = seg_left,
231 COMMUTATOR = '>>',
232 RESTRICT = positionsel,
233 JOIN = positionjoinsel
236 CREATE OPERATOR &< (
237 LEFTARG = seg,
238 RIGHTARG = seg,
239 PROCEDURE = seg_over_left,
240 RESTRICT = positionsel,
241 JOIN = positionjoinsel
244 CREATE OPERATOR && (
245 LEFTARG = seg,
246 RIGHTARG = seg,
247 PROCEDURE = seg_overlap,
248 COMMUTATOR = '&&',
249 RESTRICT = areasel,
250 JOIN = areajoinsel
253 CREATE OPERATOR &> (
254 LEFTARG = seg,
255 RIGHTARG = seg,
256 PROCEDURE = seg_over_right,
257 RESTRICT = positionsel,
258 JOIN = positionjoinsel
261 CREATE OPERATOR >> (
262 LEFTARG = seg,
263 RIGHTARG = seg,
264 PROCEDURE = seg_right,
265 COMMUTATOR = '<<',
266 RESTRICT = positionsel,
267 JOIN = positionjoinsel
270 CREATE OPERATOR = (
271 LEFTARG = seg,
272 RIGHTARG = seg,
273 PROCEDURE = seg_same,
274 COMMUTATOR = '=',
275 NEGATOR = '<>',
276 RESTRICT = eqsel,
277 JOIN = eqjoinsel,
278 MERGES
281 CREATE OPERATOR <> (
282 LEFTARG = seg,
283 RIGHTARG = seg,
284 PROCEDURE = seg_different,
285 COMMUTATOR = '<>',
286 NEGATOR = '=',
287 RESTRICT = neqsel,
288 JOIN = neqjoinsel
291 CREATE OPERATOR @> (
292 LEFTARG = seg,
293 RIGHTARG = seg,
294 PROCEDURE = seg_contains,
295 COMMUTATOR = '<@',
296 RESTRICT = contsel,
297 JOIN = contjoinsel
300 CREATE OPERATOR <@ (
301 LEFTARG = seg,
302 RIGHTARG = seg,
303 PROCEDURE = seg_contained,
304 COMMUTATOR = '@>',
305 RESTRICT = contsel,
306 JOIN = contjoinsel
309 -- obsolete:
310 CREATE OPERATOR @ (
311 LEFTARG = seg,
312 RIGHTARG = seg,
313 PROCEDURE = seg_contains,
314 COMMUTATOR = '~',
315 RESTRICT = contsel,
316 JOIN = contjoinsel
319 CREATE OPERATOR ~ (
320 LEFTARG = seg,
321 RIGHTARG = seg,
322 PROCEDURE = seg_contained,
323 COMMUTATOR = '@',
324 RESTRICT = contsel,
325 JOIN = contjoinsel
329 -- define the GiST support methods
330 CREATE OR REPLACE FUNCTION gseg_consistent(internal,seg,int,oid,internal)
331 RETURNS bool
332 AS 'MODULE_PATHNAME'
333 LANGUAGE C IMMUTABLE STRICT;
335 CREATE OR REPLACE FUNCTION gseg_compress(internal)
336 RETURNS internal
337 AS 'MODULE_PATHNAME'
338 LANGUAGE C IMMUTABLE STRICT;
340 CREATE OR REPLACE FUNCTION gseg_decompress(internal)
341 RETURNS internal
342 AS 'MODULE_PATHNAME'
343 LANGUAGE C IMMUTABLE STRICT;
345 CREATE OR REPLACE FUNCTION gseg_penalty(internal,internal,internal)
346 RETURNS internal
347 AS 'MODULE_PATHNAME'
348 LANGUAGE C IMMUTABLE STRICT;
350 CREATE OR REPLACE FUNCTION gseg_picksplit(internal, internal)
351 RETURNS internal
352 AS 'MODULE_PATHNAME'
353 LANGUAGE C IMMUTABLE STRICT;
355 CREATE OR REPLACE FUNCTION gseg_union(internal, internal)
356 RETURNS seg
357 AS 'MODULE_PATHNAME'
358 LANGUAGE C IMMUTABLE STRICT;
360 CREATE OR REPLACE FUNCTION gseg_same(seg, seg, internal)
361 RETURNS internal
362 AS 'MODULE_PATHNAME'
363 LANGUAGE C IMMUTABLE STRICT;
366 -- Create the operator classes for indexing
368 CREATE OPERATOR CLASS seg_ops
369 DEFAULT FOR TYPE seg USING btree AS
370 OPERATOR 1 < ,
371 OPERATOR 2 <= ,
372 OPERATOR 3 = ,
373 OPERATOR 4 >= ,
374 OPERATOR 5 > ,
375 FUNCTION 1 seg_cmp(seg, seg);
377 CREATE OPERATOR CLASS gist_seg_ops
378 DEFAULT FOR TYPE seg USING gist
380 OPERATOR 1 << ,
381 OPERATOR 2 &< ,
382 OPERATOR 3 && ,
383 OPERATOR 4 &> ,
384 OPERATOR 5 >> ,
385 OPERATOR 6 = ,
386 OPERATOR 7 @> ,
387 OPERATOR 8 <@ ,
388 OPERATOR 13 @ ,
389 OPERATOR 14 ~ ,
390 FUNCTION 1 gseg_consistent (internal, seg, int, oid, internal),
391 FUNCTION 2 gseg_union (internal, internal),
392 FUNCTION 3 gseg_compress (internal),
393 FUNCTION 4 gseg_decompress (internal),
394 FUNCTION 5 gseg_penalty (internal, internal, internal),
395 FUNCTION 6 gseg_picksplit (internal, internal),
396 FUNCTION 7 gseg_same (seg, seg, internal);