4
4
5
5
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
6
6
\echo Use " ALTER EXTENSION " " babelfishpg_common" " UPDATE TO '4.7.0'" to load this file. \quit
7
+
8
+ SELECT set_config(' search_path' , ' sys, ' || current_setting(' search_path' ), false);
9
+
10
+ -- Operator class for numeric_ops to incorporate various operator between numeric and int4 for Index scan
11
+ DO $$
12
+ BEGIN
13
+ IF NOT EXISTS(SELECT 1 FROM pg_opclass opc JOIN pg_opfamily opf ON opc .opcfamily = opf .oid
14
+ WHERE opc .opcname = ' numeric_int4_ops' AND opc .opcnamespace = ' sys' ::regnamespace
15
+ AND opf .opfname = ' numeric_ops' ) THEN
16
+
17
+ CREATE OPERATOR CLASS sys .numeric_int4_ops FOR TYPE numeric
18
+ USING btree FAMILY numeric_ops AS
19
+ OPERATOR 1 sys.< (numeric , int4),
20
+ OPERATOR 2 sys.<= (numeric , int4),
21
+ OPERATOR 3 sys.= (numeric , int4),
22
+ OPERATOR 4 sys.>= (numeric , int4),
23
+ OPERATOR 5 sys.> (numeric , int4),
24
+ FUNCTION 1 sys .numeric_int4_cmp (numeric , int4);
25
+ END IF;
26
+ END $$;
27
+
28
+ -- Operator class for numeric_ops to incorporate various operator between int4 and numeric for Index scan
29
+ DO $$
30
+ BEGIN
31
+ IF NOT EXISTS(SELECT 1 FROM pg_opclass opc JOIN pg_opfamily opf ON opc .opcfamily = opf .oid
32
+ WHERE opc .opcname = ' int4_numeric_ops' AND opc .opcnamespace = ' sys' ::regnamespace
33
+ AND opf .opfname = ' numeric_ops' ) THEN
34
+
35
+ CREATE OPERATOR CLASS sys .int4_numeric_ops FOR TYPE numeric
36
+ USING btree FAMILY numeric_ops AS
37
+ OPERATOR 1 sys.< (int4, numeric ),
38
+ OPERATOR 2 sys.<= (int4, numeric ),
39
+ OPERATOR 3 sys.= (int4, numeric ),
40
+ OPERATOR 4 sys.>= (int4, numeric ),
41
+ OPERATOR 5 sys.> (int4, numeric ),
42
+ FUNCTION 1 sys .int4_numeric_cmp (int4, numeric );
43
+ END IF;
44
+ END $$;
45
+
46
+ -- Operator class for numeric_ops to incorporate various operator between numeric and int2 for Index scan
47
+ DO $$
48
+ BEGIN
49
+ IF NOT EXISTS(SELECT 1 FROM pg_opclass opc JOIN pg_opfamily opf ON opc .opcfamily = opf .oid
50
+ WHERE opc .opcname = ' numeric_int2_ops' AND opc .opcnamespace = ' sys' ::regnamespace
51
+ AND opf .opfname = ' numeric_ops' ) THEN
52
+
53
+ CREATE OPERATOR CLASS sys .numeric_int2_ops FOR TYPE numeric
54
+ USING btree FAMILY numeric_ops AS
55
+ OPERATOR 1 sys.< (numeric , int2),
56
+ OPERATOR 2 sys.<= (numeric , int2),
57
+ OPERATOR 3 sys.= (numeric , int2),
58
+ OPERATOR 4 sys.>= (numeric , int2),
59
+ OPERATOR 5 sys.> (numeric , int2),
60
+ FUNCTION 1 sys .numeric_int2_cmp (numeric , int2);
61
+ END IF;
62
+ END $$;
63
+
64
+ -- Operator class for numeric_ops to incorporate various operator between int2 and numeric for Index scan
65
+ DO $$
66
+ BEGIN
67
+ IF NOT EXISTS(SELECT 1 FROM pg_opclass opc JOIN pg_opfamily opf ON opc .opcfamily = opf .oid
68
+ WHERE opc .opcname = ' int2_numeric_ops' AND opc .opcnamespace = ' sys' ::regnamespace
69
+ AND opf .opfname = ' numeric_ops' ) THEN
70
+
71
+ CREATE OPERATOR CLASS sys .int2_numeric_ops FOR TYPE numeric
72
+ USING btree FAMILY numeric_ops AS
73
+ OPERATOR 1 sys.< (int2, numeric ),
74
+ OPERATOR 2 sys.<= (int2, numeric ),
75
+ OPERATOR 3 sys.= (int2, numeric ),
76
+ OPERATOR 4 sys.>= (int2, numeric ),
77
+ OPERATOR 5 sys.> (int2, numeric ),
78
+ FUNCTION 1 sys .int2_numeric_cmp (int2, numeric );
79
+ END IF;
80
+ END $$;
81
+
82
+ -- Operator class for numeric_ops to incorporate various operator int8 and numeric for Index scan
83
+ DO $$
84
+ BEGIN
85
+ IF NOT EXISTS(SELECT 1 FROM pg_opclass opc JOIN pg_opfamily opf ON opc .opcfamily = opf .oid
86
+ WHERE opc .opcname = ' int8_numeric_ops' AND opc .opcnamespace = ' sys' ::regnamespace
87
+ AND opf .opfname = ' numeric_ops' ) THEN
88
+
89
+ CREATE OPERATOR CLASS sys .int8_numeric_ops FOR TYPE numeric
90
+ USING btree FAMILY numeric_ops AS
91
+ OPERATOR 1 sys.< (int8, numeric ),
92
+ OPERATOR 2 sys.<= (int8, numeric ),
93
+ OPERATOR 3 sys.= (int8, numeric ),
94
+ OPERATOR 4 sys.>= (int8, numeric ),
95
+ OPERATOR 5 sys.> (int8, numeric ),
96
+ FUNCTION 1 sys .int8_numeric_cmp (int8, numeric );
97
+ END IF;
98
+ END $$;
99
+
100
+ -- Operator class for numeric_ops to incorporate various operator between numeric and int8 for Index scan
101
+ DO $$
102
+ BEGIN
103
+ IF NOT EXISTS(SELECT 1 FROM pg_opclass opc JOIN pg_opfamily opf ON opc .opcfamily = opf .oid
104
+ WHERE opc .opcname = ' numeric_int8_ops' AND opc .opcnamespace = ' sys' ::regnamespace
105
+ AND opf .opfname = ' numeric_ops' ) THEN
106
+
107
+ CREATE OPERATOR CLASS sys .numeric_int8_ops FOR TYPE numeric
108
+ USING btree FAMILY numeric_ops AS
109
+ OPERATOR 1 sys.< (numeric , int8),
110
+ OPERATOR 2 sys.<= (numeric , int8),
111
+ OPERATOR 3 sys.= (numeric , int8),
112
+ OPERATOR 4 sys.>= (numeric , int8),
113
+ OPERATOR 5 sys.> (numeric , int8),
114
+ FUNCTION 1 sys .numeric_int8_cmp (numeric , int8);
115
+ END IF;
116
+ END $$;
117
+
118
+ -- Reset search_path to not affect any subsequent scripts
119
+ SELECT set_config(' search_path' , trim (leading ' sys, ' from current_setting(' search_path' )), false);
0 commit comments