-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgis_mock.sql
8407 lines (7263 loc) · 284 KB
/
postgis_mock.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
--
--
-- PostGIS - Spatial Types for PostgreSQL
-- http://postgis.net
-- Copyright 2001-2003 Refractions Research Inc.
--
-- This is free software; you can redistribute and/or modify it under
-- the terms of the GNU General Public Licence. See the COPYING file.
--
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
--
-- WARNING: Any change in this file must be evaluated for compatibility.
-- Changes cleanly handled by postgis_upgrade.sql are fine,
-- other changes will require a bump in Major version.
-- Currently only function replaceble by CREATE OR REPLACE
-- are cleanly handled.
--
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-- INSTALL VERSION: '3.5.0'
-- Check that no other postgis is installed
-- Let the user know about a deprecated signature and its new name, if any
CREATE OR REPLACE FUNCTION _postgis_deprecate(oldname text, newname text, version text)
RETURNS void AS
$$
DECLARE
curver_text text;
BEGIN
--
-- Raises a NOTICE if it was deprecated in this version,
-- a WARNING if in a previous version (only up to minor version checked)
--
curver_text := '3.5.0';
IF pg_catalog.split_part(curver_text,'.',1)::int > pg_catalog.split_part(version,'.',1)::int OR
( pg_catalog.split_part(curver_text,'.',1) = pg_catalog.split_part(version,'.',1) AND
pg_catalog.split_part(curver_text,'.',2) != split_part(version,'.',2) )
THEN
RAISE WARNING '% signature was deprecated in %. Please use %', oldname, version, newname;
ELSE
RAISE DEBUG '% signature was deprecated in %. Please use %', oldname, version, newname;
END IF;
END;
$$ LANGUAGE 'plpgsql' IMMUTABLE STRICT COST 250;
-------------------------------------------------------------------
-- SPHEROID TYPE
-------------------------------------------------------------------
CREATE OR REPLACE FUNCTION spheroid_in(cstring)
RETURNS spheroid
AS '$libdir/postgis-3.5','ellipsoid_in'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
CREATE OR REPLACE FUNCTION spheroid_out(spheroid)
RETURNS cstring
AS '$libdir/postgis-3.5','ellipsoid_out'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
-- Availability: 0.5.0
CREATE TYPE spheroid (
alignment = double,
internallength = 65,
input = spheroid_in,
output = spheroid_out
);
-------------------------------------------------------------------
-- GEOMETRY TYPE (lwgeom)
-------------------------------------------------------------------
CREATE OR REPLACE FUNCTION geometry_in(cstring)
RETURNS geometry
AS '$libdir/postgis-3.5','LWGEOM_in'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
CREATE OR REPLACE FUNCTION geometry_out(geometry)
RETURNS cstring
AS '$libdir/postgis-3.5','LWGEOM_out'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_typmod_in(cstring[])
RETURNS integer
AS '$libdir/postgis-3.5','geometry_typmod_in'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_typmod_out(integer)
RETURNS cstring
AS '$libdir/postgis-3.5','postgis_typmod_out'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
CREATE OR REPLACE FUNCTION geometry_analyze(internal)
RETURNS bool
AS '$libdir/postgis-3.5', 'gserialized_analyze_nd'
LANGUAGE 'c' VOLATILE STRICT;
CREATE OR REPLACE FUNCTION geometry_recv(internal)
RETURNS geometry
AS '$libdir/postgis-3.5','LWGEOM_recv'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
CREATE OR REPLACE FUNCTION geometry_send(geometry)
RETURNS bytea
AS '$libdir/postgis-3.5','LWGEOM_send'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
-- Availability: 0.1.0
CREATE TYPE geometry (
internallength = variable,
input = geometry_in,
output = geometry_out,
send = geometry_send,
receive = geometry_recv,
typmod_in = geometry_typmod_in,
typmod_out = geometry_typmod_out,
delimiter = ':',
alignment = double,
analyze = geometry_analyze,
storage = main
);
-- Availability: 2.0.0
-- Special cast for enforcing the typmod restrictions
CREATE OR REPLACE FUNCTION geometry(geometry, integer, boolean)
RETURNS geometry
AS '$libdir/postgis-3.5','geometry_enforce_typmod'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
-- Availability: 2.0.0
CREATE CAST (geometry AS geometry) WITH FUNCTION geometry(geometry, integer, boolean) AS IMPLICIT;
-- Availability: 2.1.0
CREATE OR REPLACE FUNCTION geometry(point)
RETURNS geometry
AS '$libdir/postgis-3.5','point_to_geometry'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
-- Availability: 2.1.0
CREATE OR REPLACE FUNCTION point(geometry)
RETURNS point
AS '$libdir/postgis-3.5','geometry_to_point'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
-- Availability: 2.1.0
CREATE OR REPLACE FUNCTION geometry(path)
RETURNS geometry
AS '$libdir/postgis-3.5','path_to_geometry'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
-- Availability: 2.1.0
CREATE OR REPLACE FUNCTION path(geometry)
RETURNS path
AS '$libdir/postgis-3.5','geometry_to_path'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
-- Availability: 2.1.0
CREATE OR REPLACE FUNCTION geometry(polygon)
RETURNS geometry
AS '$libdir/postgis-3.5','polygon_to_geometry'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
-- Availability: 2.1.0
CREATE OR REPLACE FUNCTION polygon(geometry)
RETURNS polygon
AS '$libdir/postgis-3.5','geometry_to_polygon'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
CREATE CAST (geometry AS point) WITH FUNCTION point(geometry);
CREATE CAST (point AS geometry) WITH FUNCTION geometry(point);
CREATE CAST (geometry AS path) WITH FUNCTION path(geometry);
CREATE CAST (path AS geometry) WITH FUNCTION geometry(path);
CREATE CAST (geometry AS polygon) WITH FUNCTION polygon(geometry);
CREATE CAST (polygon AS geometry) WITH FUNCTION geometry(polygon);
-------------------------------------------------------------------
-- BOX3D TYPE
-- Point coordinate data access
-------------------------------------------
-- PostGIS equivalent function: X(geometry)
CREATE OR REPLACE FUNCTION ST_X(geometry)
RETURNS float8
AS '$libdir/postgis-3.5','LWGEOM_x_point'
LANGUAGE 'c' IMMUTABLE STRICT
PARALLEL SAFE COST 1;
-- PostGIS equivalent function: Y(geometry)
CREATE OR REPLACE FUNCTION ST_Y(geometry)
RETURNS float8
AS '$libdir/postgis-3.5','LWGEOM_y_point'
LANGUAGE 'c' IMMUTABLE STRICT
PARALLEL SAFE COST 1;
-- Availability: 1.2.2
CREATE OR REPLACE FUNCTION ST_Z(geometry)
RETURNS float8
AS '$libdir/postgis-3.5','LWGEOM_z_point'
LANGUAGE 'c' IMMUTABLE STRICT
PARALLEL SAFE COST 1;
-- Availability: 1.2.2
CREATE OR REPLACE FUNCTION ST_M(geometry)
RETURNS float8
AS '$libdir/postgis-3.5','LWGEOM_m_point'
LANGUAGE 'c' IMMUTABLE STRICT
PARALLEL SAFE COST 1;
-------------------------------------------------------------------
CREATE OR REPLACE FUNCTION box3d_in(cstring)
RETURNS box3d
AS '$libdir/postgis-3.5', 'BOX3D_in'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
CREATE OR REPLACE FUNCTION box3d_out(box3d)
RETURNS cstring
AS '$libdir/postgis-3.5', 'BOX3D_out'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
-- Availability: 0.1.0
CREATE TYPE box3d (
alignment = double,
internallength = 52,
input = box3d_in,
output = box3d_out
);
-----------------------------------------------------------------------
-- BOX2D
-----------------------------------------------------------------------
CREATE OR REPLACE FUNCTION box2d_in(cstring)
RETURNS box2d
AS '$libdir/postgis-3.5','BOX2D_in'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
CREATE OR REPLACE FUNCTION box2d_out(box2d)
RETURNS cstring
AS '$libdir/postgis-3.5','BOX2D_out'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
-- Availability: 0.8.2
CREATE TYPE box2d (
internallength = 65,
input = box2d_in,
output = box2d_out,
storage = plain
);
-------------------------------------------------------------------
-- BOX2DF TYPE (INTERNAL ONLY)
-------------------------------------------------------------------
--
-- Box2Df type is used by the GiST index bindings.
-- In/out functions are stubs, as all access should be internal.
---
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION box2df_in(cstring)
RETURNS box2df
AS '$libdir/postgis-3.5','box2df_in'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION box2df_out(box2df)
RETURNS cstring
AS '$libdir/postgis-3.5','box2df_out'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
-- Availability: 2.0.0
CREATE TYPE box2df (
internallength = 16,
input = box2df_in,
output = box2df_out,
storage = plain,
alignment = double
);
-------------------------------------------------------------------
-- GIDX TYPE (INTERNAL ONLY)
-------------------------------------------------------------------
--
-- GIDX type is used by the N-D and GEOGRAPHY GiST index bindings.
-- In/out functions are stubs, as all access should be internal.
---
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION gidx_in(cstring)
RETURNS gidx
AS '$libdir/postgis-3.5','gidx_in'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION gidx_out(gidx)
RETURNS cstring
AS '$libdir/postgis-3.5','gidx_out'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
-- Availability: 1.5.0
CREATE TYPE gidx (
internallength = variable,
input = gidx_in,
output = gidx_out,
storage = plain,
alignment = double
);
-------------------------------------------------------------------
-- BTREE indexes
-------------------------------------------------------------------
CREATE OR REPLACE FUNCTION geometry_lt(geom1 geometry, geom2 geometry)
RETURNS bool
AS '$libdir/postgis-3.5', 'lwgeom_lt'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
CREATE OR REPLACE FUNCTION geometry_le(geom1 geometry, geom2 geometry)
RETURNS bool
AS '$libdir/postgis-3.5', 'lwgeom_le'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
CREATE OR REPLACE FUNCTION geometry_gt(geom1 geometry, geom2 geometry)
RETURNS bool
AS '$libdir/postgis-3.5', 'lwgeom_gt'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
CREATE OR REPLACE FUNCTION geometry_ge(geom1 geometry, geom2 geometry)
RETURNS bool
AS '$libdir/postgis-3.5', 'lwgeom_ge'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
CREATE OR REPLACE FUNCTION geometry_eq(geom1 geometry, geom2 geometry)
RETURNS bool
AS '$libdir/postgis-3.5', 'lwgeom_eq'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
CREATE OR REPLACE FUNCTION geometry_neq(geom1 geometry, geom2 geometry)
RETURNS bool
AS '$libdir/postgis-3.5', 'lwgeom_neq'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
CREATE OR REPLACE FUNCTION geometry_cmp(geom1 geometry, geom2 geometry)
RETURNS integer
AS '$libdir/postgis-3.5', 'lwgeom_cmp'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
-- Availability: 3.0.0
CREATE OR REPLACE FUNCTION geometry_sortsupport(internal)
RETURNS void
AS '$libdir/postgis-3.5', 'lwgeom_sortsupport'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
--
-- Sorting operators for Btree
--
-- Availability: 0.9.0
CREATE OPERATOR < (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_lt,
COMMUTATOR = '>', NEGATOR = '>=',
RESTRICT = contsel, JOIN = contjoinsel
);
-- Availability: 0.9.0
CREATE OPERATOR <= (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_le,
COMMUTATOR = '>=', NEGATOR = '>',
RESTRICT = contsel, JOIN = contjoinsel
);
-- Availability: 0.9.0
CREATE OPERATOR = (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_eq,
COMMUTATOR = '=', NEGATOR = '<>',
RESTRICT = contsel, JOIN = contjoinsel, HASHES, MERGES
);
-- Availability: 3.5.0
CREATE OPERATOR <> (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_neq,
COMMUTATOR = '<>', NEGATOR = '=',
RESTRICT = contsel, JOIN = contjoinsel, HASHES, MERGES
);
-- Availability: 0.9.0
CREATE OPERATOR >= (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_ge,
COMMUTATOR = '<=', NEGATOR = '<',
RESTRICT = contsel, JOIN = contjoinsel
);
-- Availability: 0.9.0
CREATE OPERATOR > (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_gt,
COMMUTATOR = '<', NEGATOR = '<=',
RESTRICT = contsel, JOIN = contjoinsel
);
-- Availability: 0.9.0
CREATE OPERATOR CLASS btree_geometry_ops
DEFAULT FOR TYPE geometry USING btree AS
OPERATOR 1 < ,
OPERATOR 2 <= ,
OPERATOR 3 = ,
OPERATOR 4 >= ,
OPERATOR 5 > ,
FUNCTION 1 geometry_cmp (geom1 geometry, geom2 geometry),
-- Availability: 3.0.0
FUNCTION 2 geometry_sortsupport(internal);
--
-- Sorting operators for Btree
--
-- Availability: 2.5.0
CREATE OR REPLACE FUNCTION geometry_hash(geometry)
RETURNS integer
AS '$libdir/postgis-3.5','lwgeom_hash'
LANGUAGE 'c' STRICT IMMUTABLE PARALLEL SAFE;
-- Availability: 2.5.0
CREATE OPERATOR CLASS hash_geometry_ops
DEFAULT FOR TYPE geometry USING hash AS
OPERATOR 1 = ,
FUNCTION 1 geometry_hash(geometry);
-----------------------------------------------------------------------------
-- GiST 2D GEOMETRY-over-GSERIALIZED INDEX
-----------------------------------------------------------------------------
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
-- GiST Support Functions
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_gist_distance_2d(internal,geometry,integer)
RETURNS float8
AS '$libdir/postgis-3.5' ,'gserialized_gist_distance_2d'
LANGUAGE 'c' PARALLEL SAFE;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_gist_consistent_2d(internal,geometry,integer)
RETURNS bool
AS '$libdir/postgis-3.5' ,'gserialized_gist_consistent_2d'
LANGUAGE 'c' PARALLEL SAFE;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_gist_compress_2d(internal)
RETURNS internal
AS '$libdir/postgis-3.5','gserialized_gist_compress_2d'
LANGUAGE 'c' PARALLEL SAFE;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_gist_penalty_2d(internal,internal,internal)
RETURNS internal
AS '$libdir/postgis-3.5' ,'gserialized_gist_penalty_2d'
LANGUAGE 'c' PARALLEL SAFE;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_gist_picksplit_2d(internal, internal)
RETURNS internal
AS '$libdir/postgis-3.5' ,'gserialized_gist_picksplit_2d'
LANGUAGE 'c' PARALLEL SAFE;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_gist_union_2d(bytea, internal)
RETURNS internal
AS '$libdir/postgis-3.5' ,'gserialized_gist_union_2d'
LANGUAGE 'c' PARALLEL SAFE;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_gist_same_2d(geom1 geometry, geom2 geometry, internal)
RETURNS internal
AS '$libdir/postgis-3.5' ,'gserialized_gist_same_2d'
LANGUAGE 'c' PARALLEL SAFE;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_gist_decompress_2d(internal)
RETURNS internal
AS '$libdir/postgis-3.5' ,'gserialized_gist_decompress_2d'
LANGUAGE 'c' PARALLEL SAFE;
-- Availability: 3.2.0
CREATE OR REPLACE FUNCTION geometry_gist_sortsupport_2d(internal)
RETURNS void
AS '$libdir/postgis-3.5', 'gserialized_gist_sortsupport_2d'
LANGUAGE 'c' STRICT;
-----------------------------------------------------------------------------
-- Availability: 2.1.0
-- Given a table, column and query geometry, returns the estimate of what proportion
-- of the table would be returned by a query using the &&/&&& operators. The mode
-- changes whether the estimate is in x/y only or in all available dimensions.
CREATE OR REPLACE FUNCTION _postgis_selectivity(tbl regclass, att_name text, geom geometry, mode text default '2')
RETURNS float8
AS '$libdir/postgis-3.5', '_postgis_gserialized_sel'
LANGUAGE 'c' STRICT PARALLEL SAFE;
-- Availability: 2.1.0
-- Given a two tables and columns, returns estimate of the proportion of rows
-- a &&/&&& join will return relative to the number of rows an unconstrained
-- table join would return. Mode flips result between evaluation in x/y only
-- and evaluation in all available dimensions.
CREATE OR REPLACE FUNCTION _postgis_join_selectivity(regclass, text, regclass, text, text default '2')
RETURNS float8
AS '$libdir/postgis-3.5', '_postgis_gserialized_joinsel'
LANGUAGE 'c' STRICT PARALLEL SAFE;
-- Availability: 2.1.0
-- Given a table and a column, returns the statistics information stored by
-- PostgreSQL, in a JSON text form. Mode determines whether the 2D statistics
-- or the ND statistics are returned.
CREATE OR REPLACE FUNCTION _postgis_stats(tbl regclass, att_name text, text default '2')
RETURNS text
AS '$libdir/postgis-3.5', '_postgis_gserialized_stats'
LANGUAGE 'c' STRICT PARALLEL SAFE;
-- Availability: 2.5.0
-- Given a table and a column, returns the extent of all boxes in the
-- first page of the index (the head of the index)
CREATE OR REPLACE FUNCTION _postgis_index_extent(tbl regclass, col text)
RETURNS box2d
AS '$libdir/postgis-3.5','_postgis_gserialized_index_extent'
LANGUAGE 'c' STABLE STRICT;
-- Availability: 2.1.0
CREATE OR REPLACE FUNCTION gserialized_gist_sel_2d (internal, oid, internal, integer)
RETURNS float8
AS '$libdir/postgis-3.5', 'gserialized_gist_sel_2d'
LANGUAGE 'c' PARALLEL SAFE;
-- Availability: 2.1.0
CREATE OR REPLACE FUNCTION gserialized_gist_sel_nd (internal, oid, internal, integer)
RETURNS float8
AS '$libdir/postgis-3.5', 'gserialized_gist_sel_nd'
LANGUAGE 'c' PARALLEL SAFE;
-- Availability: 2.1.0
CREATE OR REPLACE FUNCTION gserialized_gist_joinsel_2d (internal, oid, internal, smallint)
RETURNS float8
AS '$libdir/postgis-3.5', 'gserialized_gist_joinsel_2d'
LANGUAGE 'c' PARALLEL SAFE;
-- Availability: 2.1.0
CREATE OR REPLACE FUNCTION gserialized_gist_joinsel_nd (internal, oid, internal, smallint)
RETURNS float8
AS '$libdir/postgis-3.5', 'gserialized_gist_joinsel_nd'
LANGUAGE 'c' PARALLEL SAFE;
-----------------------------------------------------------------------------
-- GEOMETRY Operators
-----------------------------------------------------------------------------
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
-- 2D GEOMETRY Operators
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_overlaps(geom1 geometry, geom2 geometry)
RETURNS boolean
AS '$libdir/postgis-3.5' ,'gserialized_overlaps_2d'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
-- Availability: 0.1.0
-- Changed: 2.0.0 use gserialized selectivity estimators
CREATE OPERATOR && (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_overlaps,
COMMUTATOR = '&&'
);
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_same(geom1 geometry, geom2 geometry)
RETURNS boolean
AS '$libdir/postgis-3.5' ,'gserialized_same_2d'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
-- Availability: 0.1.0
CREATE OPERATOR ~= (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_same,
RESTRICT = contsel, JOIN = contjoinsel
);
-- As of 2.2.0 this no longer returns the centroid/centroid distance, it
-- returns the actual distance, to support the 'recheck' functionality
-- enabled in the KNN operator
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_distance_centroid(geom1 geometry, geom2 geometry)
RETURNS float8
AS '$libdir/postgis-3.5', 'ST_Distance'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 250;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_distance_box(geom1 geometry, geom2 geometry)
RETURNS float8
AS '$libdir/postgis-3.5', 'gserialized_distance_box_2d'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
-- Availability: 2.0.0
CREATE OPERATOR <-> (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_distance_centroid,
COMMUTATOR = '<->'
);
-- Availability: 2.0.0
CREATE OPERATOR <#> (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_distance_box,
COMMUTATOR = '<#>'
);
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_contains(geom1 geometry, geom2 geometry)
RETURNS bool
AS '$libdir/postgis-3.5', 'gserialized_contains_2d'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_within(geom1 geometry, geom2 geometry)
RETURNS bool
AS '$libdir/postgis-3.5', 'gserialized_within_2d'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
-- Availability: 0.1.0
-- Updated: 3.4.0 changed to use selectivity estimates
CREATE OPERATOR @ (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_within,
COMMUTATOR = '~'
-- Updated: 3.4.0 to use selectivity estimator,
-- Updated: 3.4.0 to use join selectivity estimator
);
-- Availability: 0.1.0
-- Updated: 3.4.0 changed to use selectivity estimates
CREATE OPERATOR ~ (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_contains,
COMMUTATOR = '@'
-- Updated: 3.4.0 to use specialized selectivity estimator,
-- Updated: 3.4.0 to use join specialized selectivity estimator
);
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_left(geom1 geometry, geom2 geometry)
RETURNS bool
AS '$libdir/postgis-3.5', 'gserialized_left_2d'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
-- Availability: 0.1.0
CREATE OPERATOR << (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_left,
COMMUTATOR = '>>',
RESTRICT = positionsel, JOIN = positionjoinsel
);
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_overleft(geom1 geometry, geom2 geometry)
RETURNS bool
AS '$libdir/postgis-3.5', 'gserialized_overleft_2d'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
-- Availability: 0.1.0
CREATE OPERATOR &< (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_overleft,
RESTRICT = positionsel, JOIN = positionjoinsel
);
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_below(geom1 geometry, geom2 geometry)
RETURNS bool
AS '$libdir/postgis-3.5', 'gserialized_below_2d'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
-- Availability: 0.1.0
CREATE OPERATOR <<| (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_below,
COMMUTATOR = '|>>',
RESTRICT = positionsel, JOIN = positionjoinsel
);
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_overbelow(geom1 geometry, geom2 geometry)
RETURNS bool
AS '$libdir/postgis-3.5', 'gserialized_overbelow_2d'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
-- Availability: 0.1.0
CREATE OPERATOR &<| (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_overbelow,
RESTRICT = positionsel, JOIN = positionjoinsel
);
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_overright(geom1 geometry, geom2 geometry)
RETURNS bool
AS '$libdir/postgis-3.5', 'gserialized_overright_2d'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
-- Availability: 0.1.0
CREATE OPERATOR &> (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_overright,
RESTRICT = positionsel, JOIN = positionjoinsel
);
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_right(geom1 geometry, geom2 geometry)
RETURNS bool
AS '$libdir/postgis-3.5', 'gserialized_right_2d'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
-- Availability: 0.1.0
CREATE OPERATOR >> (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_right,
COMMUTATOR = '<<',
RESTRICT = positionsel, JOIN = positionjoinsel
);
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_overabove(geom1 geometry, geom2 geometry)
RETURNS bool
AS '$libdir/postgis-3.5', 'gserialized_overabove_2d'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
-- Availability: 0.1.0
CREATE OPERATOR |&> (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_overabove,
RESTRICT = positionsel, JOIN = positionjoinsel
);
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_above(geom1 geometry, geom2 geometry)
RETURNS bool
AS '$libdir/postgis-3.5', 'gserialized_above_2d'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
-- Availability: 0.1.0
CREATE OPERATOR |>> (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_above,
COMMUTATOR = '<<|',
RESTRICT = positionsel, JOIN = positionjoinsel
);
-- Availability: 2.0.0
CREATE OPERATOR CLASS gist_geometry_ops_2d
DEFAULT FOR TYPE geometry USING GIST AS
STORAGE box2df,
OPERATOR 1 << ,
OPERATOR 2 &< ,
OPERATOR 3 && ,
OPERATOR 4 &> ,
OPERATOR 5 >> ,
OPERATOR 6 ~= ,
OPERATOR 7 ~ ,
OPERATOR 8 @ ,
OPERATOR 9 &<| ,
OPERATOR 10 <<| ,
OPERATOR 11 |>> ,
OPERATOR 12 |&> ,
OPERATOR 13 <-> FOR ORDER BY pg_catalog.float_ops,
OPERATOR 14 <#> FOR ORDER BY pg_catalog.float_ops,
--
-- Sort support in bulk indexing not included in the default
-- opclass for PostgreSQL versions <15 due to query performance
-- degradation caused by GiST index page overlap.
-- Since PostgreSQL 15 sorting build uses picksplit function to
-- find better partitioning for index records. This allows to
-- build indices performing similarly to those produced by default
-- method while still reducing index build time significantly.
--
-- To enable sortsupport:
-- alter operator family gist_geometry_ops_2d using gist
-- add function 11 (geometry)
-- geometry_gist_sortsupport_2d (internal);
--
-- To remove sortsupport:
-- alter operator family gist_geometry_ops_2d using gist
-- drop function 11 (geometry);
--
FUNCTION 8 geometry_gist_distance_2d (internal, geometry, integer),
FUNCTION 1 geometry_gist_consistent_2d (internal, geometry, integer),
FUNCTION 2 geometry_gist_union_2d (bytea, internal),
FUNCTION 3 geometry_gist_compress_2d (internal),
FUNCTION 4 geometry_gist_decompress_2d (internal),
FUNCTION 5 geometry_gist_penalty_2d (internal, internal, internal),
FUNCTION 6 geometry_gist_picksplit_2d (internal, internal),
FUNCTION 7 geometry_gist_same_2d (geom1 geometry, geom2 geometry, internal);
-----------------------------------------------------------------------------
-- GiST ND GEOMETRY-over-GSERIALIZED
-----------------------------------------------------------------------------
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
-- GiST Support Functions
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_gist_consistent_nd(internal,geometry,integer)
RETURNS bool
AS '$libdir/postgis-3.5' ,'gserialized_gist_consistent'
LANGUAGE 'c' PARALLEL SAFE
COST 1;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_gist_compress_nd(internal)
RETURNS internal
AS '$libdir/postgis-3.5','gserialized_gist_compress'
LANGUAGE 'c' PARALLEL SAFE
COST 1;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_gist_penalty_nd(internal,internal,internal)
RETURNS internal
AS '$libdir/postgis-3.5' ,'gserialized_gist_penalty'
LANGUAGE 'c' PARALLEL SAFE
COST 1;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_gist_picksplit_nd(internal, internal)
RETURNS internal
AS '$libdir/postgis-3.5' ,'gserialized_gist_picksplit'
LANGUAGE 'c' PARALLEL SAFE
COST 1;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_gist_union_nd(bytea, internal)
RETURNS internal
AS '$libdir/postgis-3.5' ,'gserialized_gist_union'
LANGUAGE 'c' PARALLEL SAFE
COST 1;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_gist_same_nd(geometry, geometry, internal)
RETURNS internal
AS '$libdir/postgis-3.5' ,'gserialized_gist_same'
LANGUAGE 'c' PARALLEL SAFE
COST 1;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_gist_decompress_nd(internal)
RETURNS internal
AS '$libdir/postgis-3.5' ,'gserialized_gist_decompress'
LANGUAGE 'c' PARALLEL SAFE
COST 1;
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
-- N-D GEOMETRY Operators
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geometry_overlaps_nd(geometry, geometry)
RETURNS boolean
AS '$libdir/postgis-3.5' ,'gserialized_overlaps'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
-- Availability: 2.0.0
CREATE OPERATOR &&& (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_overlaps_nd,
COMMUTATOR = '&&&'
);
-- Availability: 3.0.0
CREATE OR REPLACE FUNCTION geometry_contains_nd(geometry, geometry)
RETURNS boolean
AS '$libdir/postgis-3.5' ,'gserialized_contains'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
-- Availability: 3.0.0
CREATE OPERATOR ~~ (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_contains_nd,
COMMUTATOR = '@@'
);
-- Availability: 3.0.0
CREATE OR REPLACE FUNCTION geometry_within_nd(geometry, geometry)
RETURNS boolean
AS '$libdir/postgis-3.5' ,'gserialized_within'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
-- Availability: 3.0.0
CREATE OPERATOR @@ (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_within_nd,
COMMUTATOR = '~~'
);
-- Availability: 3.0.0
CREATE OR REPLACE FUNCTION geometry_same_nd(geometry, geometry)
RETURNS boolean
AS '$libdir/postgis-3.5' ,'gserialized_same'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 1;
-- Availability: 3.0.0
CREATE OPERATOR ~~= (
LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_same_nd,
COMMUTATOR = '~~='
);
-- Availability: 2.2.0
CREATE OR REPLACE FUNCTION geometry_distance_centroid_nd(geometry,geometry)
RETURNS float8
AS '$libdir/postgis-3.5', 'gserialized_distance_nd'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
-- Availability: 2.2.0
CREATE OPERATOR <<->> (
LEFTARG = geometry, RIGHTARG = geometry,
PROCEDURE = geometry_distance_centroid_nd,
COMMUTATOR = '<<->>'
);
--
-- This is for use with |=| operator, which does not directly use
-- ST_DistanceCPA just in case it'll ever need to change behavior
-- (operators definition cannot be altered)
--
-- Availability: 2.2.0
CREATE OR REPLACE FUNCTION geometry_distance_cpa(geometry, geometry)
RETURNS float8
AS '$libdir/postgis-3.5', 'ST_DistanceCPA'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
COST 5000;
-- Availability: 2.2.0
CREATE OPERATOR |=| (
LEFTARG = geometry, RIGHTARG = geometry,
PROCEDURE = geometry_distance_cpa,
COMMUTATOR = '|=|'
);
-- Availability: 2.2.0
CREATE OR REPLACE FUNCTION geometry_gist_distance_nd(internal,geometry,integer)
RETURNS float8
AS '$libdir/postgis-3.5', 'gserialized_gist_distance'
LANGUAGE 'c' PARALLEL SAFE
COST 1;
-- Availability: 2.0.0
CREATE OPERATOR CLASS gist_geometry_ops_nd
FOR TYPE geometry USING GIST AS
STORAGE gidx,
OPERATOR 3 &&& ,
-- Availability: 3.0.0
OPERATOR 6 ~~= ,