1 CREATE EXTENSION smlar;
2 set extra_float_digits =0;
14 opc.opcmethod = am.oid AND
16 opc.opcintype = t.oid AND
17 opc.opckeytype = k.oid AND
20 opcname | typname | opcdefault
21 ----------------------+--------------+------------
22 _bytea_sml_ops | _bytea | f
23 _char_sml_ops | _char | f
24 _cidr_sml_ops | _cidr | f
25 _date_sml_ops | _date | f
26 _float4_sml_ops | _float4 | f
27 _float8_sml_ops | _float8 | f
28 _inet_sml_ops | _inet | f
29 _int2_sml_ops | _int2 | f
30 _int4_sml_ops | _int4 | f
31 _int8_sml_ops | _int8 | f
32 _interval_sml_ops | _interval | f
33 _macaddr_sml_ops | _macaddr | f
34 _numeric_sml_ops | _numeric | f
35 _oid_sml_ops | _oid | f
36 _text_sml_ops | _text | f
37 _time_sml_ops | _time | f
38 _timestamp_sml_ops | _timestamp | f
39 _timestamptz_sml_ops | _timestamptz | f
40 _timetz_sml_ops | _timetz | f
41 _varchar_sml_ops | _varchar | f
53 opc.opcmethod = am.oid AND
55 opc.opcintype = t.oid AND
56 opc.opcname ~ '_sml_ops$'
58 opcname | typname | opcdefault
59 ----------------------+--------------+------------
60 _bit_sml_ops | _bit | f
61 _bytea_sml_ops | _bytea | f
62 _char_sml_ops | _char | f
63 _cidr_sml_ops | _cidr | f
64 _date_sml_ops | _date | f
65 _float4_sml_ops | _float4 | f
66 _float8_sml_ops | _float8 | f
67 _inet_sml_ops | _inet | f
68 _int2_sml_ops | _int2 | f
69 _int4_sml_ops | _int4 | f
70 _int8_sml_ops | _int8 | f
71 _interval_sml_ops | _interval | f
72 _macaddr_sml_ops | _macaddr | f
73 _money_sml_ops | _money | f
74 _numeric_sml_ops | _numeric | f
75 _oid_sml_ops | _oid | f
76 _text_sml_ops | _text | f
77 _time_sml_ops | _time | f
78 _timestamp_sml_ops | _timestamp | f
79 _timestamptz_sml_ops | _timestamptz | f
80 _timetz_sml_ops | _timetz | f
81 _varbit_sml_ops | _varbit | f
82 _varchar_sml_ops | _varchar | f
86 trim( leading '_' from t.typname ) || '[]' AS "Array Type",
87 gin.opcname AS "GIN operator class",
88 gist.opcname AS "GiST operator class"
93 pg_catalog.pg_opclass,
96 pg_opclass.opcmethod = pg_am.oid AND
97 pg_am.amname = 'gin' AND
98 pg_opclass.opcname ~ '_sml_ops$'
104 pg_catalog.pg_opclass,
107 pg_opclass.opcmethod = pg_am.oid AND
108 pg_am.amname = 'gist' AND
109 pg_opclass.opcname ~ '_sml_ops$'
112 gist.opcname = gin.opcname AND
113 gist.opcintype = gin.opcintype
117 t.oid = COALESCE(gist.opcintype, gin.opcintype) AND
122 Array Type | GIN operator class | GiST operator class
123 ---------------+----------------------+----------------------
124 bit[] | _bit_sml_ops |
125 bytea[] | _bytea_sml_ops | _bytea_sml_ops
126 char[] | _char_sml_ops | _char_sml_ops
127 cidr[] | _cidr_sml_ops | _cidr_sml_ops
128 date[] | _date_sml_ops | _date_sml_ops
129 float4[] | _float4_sml_ops | _float4_sml_ops
130 float8[] | _float8_sml_ops | _float8_sml_ops
131 inet[] | _inet_sml_ops | _inet_sml_ops
132 int2[] | _int2_sml_ops | _int2_sml_ops
133 int4[] | _int4_sml_ops | _int4_sml_ops
134 int8[] | _int8_sml_ops | _int8_sml_ops
135 interval[] | _interval_sml_ops | _interval_sml_ops
136 macaddr[] | _macaddr_sml_ops | _macaddr_sml_ops
137 money[] | _money_sml_ops |
138 numeric[] | _numeric_sml_ops | _numeric_sml_ops
139 oid[] | _oid_sml_ops | _oid_sml_ops
140 text[] | _text_sml_ops | _text_sml_ops
141 time[] | _time_sml_ops | _time_sml_ops
142 timestamp[] | _timestamp_sml_ops | _timestamp_sml_ops
143 timestamptz[] | _timestamptz_sml_ops | _timestamptz_sml_ops
144 timetz[] | _timetz_sml_ops | _timetz_sml_ops
145 varbit[] | _varbit_sml_ops |
146 varchar[] | _varchar_sml_ops | _varchar_sml_ops
149 SELECT set_smlar_limit(0.1);
155 SET smlar.threshold = 0.6;
157 SELECT smlar('{3,2}'::int[], '{3,2,1}');
163 SELECT smlar('{2,1}'::int[], '{3,2,1}');
169 SELECT smlar('{}'::int[], '{3,2,1}');
175 SELECT smlar('{12,10}'::int[], '{3,2,1}');
181 SELECT smlar('{123}'::int[], '{}');
187 SELECT smlar('{1,4,6}'::int[], '{1,4,6}');
193 SELECT smlar('{1,4,6}'::int[], '{6,4,1}');
199 SELECT smlar('{1,4,6}'::int[], '{5,4,6}');
205 SELECT smlar('{1,4,6}'::int[], '{5,4,6}');
211 SELECT smlar('{1,2}'::int[], '{2,2,2,2,2,1}');
217 SELECT smlar('{1,2}'::int[], '{1,2,2,2,2,2}');
223 SELECT smlar('{}'::int[], '{3}');
229 SELECT smlar('{3}'::int[], '{3}');
235 SELECT smlar('{2}'::int[], '{3}');
241 SELECT smlar('{1,4,6}'::int[], '{5,4,6}', 'N.i / (N.a + N.b)' );
247 SELECT smlar('{1,4,6}'::int[], '{5,4,6}', 'N.i / sqrt(N.a * N.b)' );
253 SELECT tsvector2textarray('qwe:12 asd:45');
259 SELECT array_unique('{12,12,1,4,1,16}'::int4[]);
265 SELECT array_unique('{12,12,1,4,1,16}'::bigint[]);
271 SELECT array_unique('{12,12,1,4,1,16}'::smallint[]);
277 SELECT array_unique('{12,12,1,4,1,16}'::text[]);
283 SELECT array_unique('{12,12,1,4,1,16}'::varchar[]);
289 SELECT inarray('{12,12,1,4,1,16}'::int[], 13::int);
295 SELECT inarray('{12,12,1,4,1,16}'::int[], 12::int);
301 SELECT inarray('{12,12,1,4,1,16}'::text[], 13::text);
307 SELECT inarray('{12,12,1,4,1,16}'::text[], 12::text);
313 SELECT inarray('{12,12,1,4,1,16}'::int[], 13::int, 0.9, 0.1);
319 SELECT inarray('{12,12,1,4,1,16}'::int[], 12::int, 0.9, 0.1);
325 SELECT inarray('{12,12,1,4,1,16}'::text[], 13::text, 0.9, 0.1);
331 SELECT inarray('{12,12,1,4,1,16}'::text[], 12::text, 0.9, 0.1);
338 CREATE OR REPLACE FUNCTION epoch2timestamp(int4)
339 RETURNS timestamp AS $$
340 SELECT ('1970-01-01 00:00:00'::timestamp + ( ($1*3600*24 + $1) ::text || ' seconds' )::interval)::timestamp;
341 $$ LANGUAGE SQL RETURNS NULL ON NULL INPUT IMMUTABLE;
342 CREATE OR REPLACE FUNCTION to_tsp_array(_int4)
343 RETURNS _timestamp AS $$
346 epoch2timestamp( $1[n] )
348 generate_series( 1, array_upper( $1, 1) - array_lower( $1, 1 ) + 1 ) AS n
350 $$ LANGUAGE SQL RETURNS NULL ON NULL INPUT IMMUTABLE;
351 CREATE OR REPLACE FUNCTION array_to_col(anyarray)
352 RETURNS SETOF anyelement AS
354 SELECT $1[n] FROM generate_series( 1, array_upper( $1, 1) - array_lower( $1, 1 ) + 1 ) AS n;
355 $$ LANGUAGE SQL RETURNS NULL ON NULL INPUT IMMUTABLE;