support pgsql versions up to 11
[smlar.git] / expected / smlar.out
1 CREATE EXTENSION smlar;
2 --sanity check
3 SELECT 
4         opc.opcname, 
5         t.typname, 
6         opc.opcdefault  
7 FROM 
8         pg_opclass opc, 
9         pg_am am, 
10         pg_type t, 
11         pg_type k 
12 WHERE 
13         opc.opcmethod = am.oid AND 
14         am.amname='gist' AND 
15         opc.opcintype = t.oid AND 
16         opc.opckeytype = k.oid AND 
17         k.typname='gsmlsign'
18 ORDER BY opc.opcname;
19        opcname        |   typname    | opcdefault 
20 ----------------------+--------------+------------
21  _bytea_sml_ops       | _bytea       | f
22  _char_sml_ops        | _char        | f
23  _cidr_sml_ops        | _cidr        | f
24  _date_sml_ops        | _date        | f
25  _float4_sml_ops      | _float4      | f
26  _float8_sml_ops      | _float8      | f
27  _inet_sml_ops        | _inet        | f
28  _int2_sml_ops        | _int2        | f
29  _int4_sml_ops        | _int4        | f
30  _int8_sml_ops        | _int8        | f
31  _interval_sml_ops    | _interval    | f
32  _macaddr_sml_ops     | _macaddr     | f
33  _numeric_sml_ops     | _numeric     | f
34  _oid_sml_ops         | _oid         | f
35  _text_sml_ops        | _text        | f
36  _time_sml_ops        | _time        | f
37  _timestamp_sml_ops   | _timestamp   | f
38  _timestamptz_sml_ops | _timestamptz | f
39  _timetz_sml_ops      | _timetz      | f
40  _varchar_sml_ops     | _varchar     | f
41 (20 rows)
42
43 SELECT 
44         opc.opcname, 
45         t.typname, 
46         opc.opcdefault  
47 FROM 
48         pg_opclass opc, 
49         pg_am am, 
50         pg_type t
51 WHERE 
52         opc.opcmethod = am.oid AND 
53         am.amname='gin' AND 
54         opc.opcintype = t.oid AND 
55         opc.opcname ~ '_sml_ops$'
56 ORDER BY opc.opcname;
57        opcname        |   typname    | opcdefault 
58 ----------------------+--------------+------------
59  _bit_sml_ops         | _bit         | f
60  _bytea_sml_ops       | _bytea       | f
61  _char_sml_ops        | _char        | f
62  _cidr_sml_ops        | _cidr        | f
63  _date_sml_ops        | _date        | f
64  _float4_sml_ops      | _float4      | f
65  _float8_sml_ops      | _float8      | f
66  _inet_sml_ops        | _inet        | f
67  _int2_sml_ops        | _int2        | f
68  _int4_sml_ops        | _int4        | f
69  _int8_sml_ops        | _int8        | f
70  _interval_sml_ops    | _interval    | f
71  _macaddr_sml_ops     | _macaddr     | f
72  _money_sml_ops       | _money       | f
73  _numeric_sml_ops     | _numeric     | f
74  _oid_sml_ops         | _oid         | f
75  _text_sml_ops        | _text        | f
76  _time_sml_ops        | _time        | f
77  _timestamp_sml_ops   | _timestamp   | f
78  _timestamptz_sml_ops | _timestamptz | f
79  _timetz_sml_ops      | _timetz      | f
80  _varbit_sml_ops      | _varbit      | f
81  _varchar_sml_ops     | _varchar     | f
82 (23 rows)
83
84 SELECT 
85     trim( leading '_'  from t.typname ) || '[]' AS "Array Type",
86     gin.opcname AS "GIN operator class",
87     gist.opcname AS "GiST operator class"
88 FROM
89     (
90         SELECT *
91         FROM
92             pg_catalog.pg_opclass,
93             pg_catalog.pg_am
94         WHERE
95             pg_opclass.opcmethod = pg_am.oid AND
96             pg_am.amname = 'gin' AND
97             pg_opclass.opcname ~ '_sml_ops$'
98     ) AS gin
99     FULL OUTER JOIN
100         (
101             SELECT *
102             FROM
103                 pg_catalog.pg_opclass,
104                 pg_catalog.pg_am
105             WHERE
106                 pg_opclass.opcmethod = pg_am.oid AND
107                 pg_am.amname = 'gist' AND
108                 pg_opclass.opcname ~ '_sml_ops$'
109         ) AS gist
110         ON (
111             gist.opcname = gin.opcname AND 
112             gist.opcintype = gin.opcintype 
113         ),
114     pg_catalog.pg_type t
115 WHERE
116     t.oid = COALESCE(gist.opcintype, gin.opcintype) AND
117     t.typarray = 0
118 ORDER BY
119     "Array Type" ASC 
120 ;
121   Array Type   |  GIN operator class  | GiST operator class  
122 ---------------+----------------------+----------------------
123  bit[]         | _bit_sml_ops         | 
124  bytea[]       | _bytea_sml_ops       | _bytea_sml_ops
125  char[]        | _char_sml_ops        | _char_sml_ops
126  cidr[]        | _cidr_sml_ops        | _cidr_sml_ops
127  date[]        | _date_sml_ops        | _date_sml_ops
128  float4[]      | _float4_sml_ops      | _float4_sml_ops
129  float8[]      | _float8_sml_ops      | _float8_sml_ops
130  inet[]        | _inet_sml_ops        | _inet_sml_ops
131  int2[]        | _int2_sml_ops        | _int2_sml_ops
132  int4[]        | _int4_sml_ops        | _int4_sml_ops
133  int8[]        | _int8_sml_ops        | _int8_sml_ops
134  interval[]    | _interval_sml_ops    | _interval_sml_ops
135  macaddr[]     | _macaddr_sml_ops     | _macaddr_sml_ops
136  money[]       | _money_sml_ops       | 
137  numeric[]     | _numeric_sml_ops     | _numeric_sml_ops
138  oid[]         | _oid_sml_ops         | _oid_sml_ops
139  text[]        | _text_sml_ops        | _text_sml_ops
140  time[]        | _time_sml_ops        | _time_sml_ops
141  timestamp[]   | _timestamp_sml_ops   | _timestamp_sml_ops
142  timestamptz[] | _timestamptz_sml_ops | _timestamptz_sml_ops
143  timetz[]      | _timetz_sml_ops      | _timetz_sml_ops
144  varbit[]      | _varbit_sml_ops      | 
145  varchar[]     | _varchar_sml_ops     | _varchar_sml_ops
146 (23 rows)
147
148 SELECT set_smlar_limit(0.1);
149  set_smlar_limit 
150 -----------------
151              0.1
152 (1 row)
153
154 SET smlar.threshold = 0.6;
155 --First checks
156 SELECT smlar('{3,2}'::int[], '{3,2,1}');
157   smlar   
158 ----------
159  0.816497
160 (1 row)
161
162 SELECT smlar('{2,1}'::int[], '{3,2,1}');
163   smlar   
164 ----------
165  0.816497
166 (1 row)
167
168 SELECT smlar('{}'::int[], '{3,2,1}');
169  smlar 
170 -------
171      0
172 (1 row)
173
174 SELECT smlar('{12,10}'::int[], '{3,2,1}');
175  smlar 
176 -------
177      0
178 (1 row)
179
180 SELECT smlar('{123}'::int[], '{}');
181  smlar 
182 -------
183      0
184 (1 row)
185
186 SELECT smlar('{1,4,6}'::int[], '{1,4,6}');
187  smlar 
188 -------
189      1
190 (1 row)
191
192 SELECT smlar('{1,4,6}'::int[], '{6,4,1}');
193  smlar 
194 -------
195      1
196 (1 row)
197
198 SELECT smlar('{1,4,6}'::int[], '{5,4,6}');
199   smlar   
200 ----------
201  0.666667
202 (1 row)
203
204 SELECT smlar('{1,4,6}'::int[], '{5,4,6}');
205   smlar   
206 ----------
207  0.666667
208 (1 row)
209
210 SELECT smlar('{1,2}'::int[], '{2,2,2,2,2,1}');
211  smlar 
212 -------
213      1
214 (1 row)
215
216 SELECT smlar('{1,2}'::int[], '{1,2,2,2,2,2}');
217  smlar 
218 -------
219      1
220 (1 row)
221
222 SELECT smlar('{}'::int[], '{3}');
223  smlar 
224 -------
225      0
226 (1 row)
227
228 SELECT smlar('{3}'::int[], '{3}');
229  smlar 
230 -------
231      1
232 (1 row)
233
234 SELECT smlar('{2}'::int[], '{3}');
235  smlar 
236 -------
237      0
238 (1 row)
239
240 SELECT smlar('{1,4,6}'::int[], '{5,4,6}', 'N.i / (N.a + N.b)' );
241   smlar   
242 ----------
243  0.333333
244 (1 row)
245
246 SELECT smlar('{1,4,6}'::int[], '{5,4,6}', 'N.i / sqrt(N.a * N.b)' );
247   smlar   
248 ----------
249  0.666667
250 (1 row)
251
252 SELECT tsvector2textarray('qwe:12 asd:45');
253  tsvector2textarray 
254 --------------------
255  {asd,qwe}
256 (1 row)
257
258 SELECT array_unique('{12,12,1,4,1,16}'::int4[]);
259  array_unique 
260 --------------
261  {1,4,12,16}
262 (1 row)
263
264 SELECT array_unique('{12,12,1,4,1,16}'::bigint[]);
265  array_unique 
266 --------------
267  {1,4,12,16}
268 (1 row)
269
270 SELECT array_unique('{12,12,1,4,1,16}'::smallint[]);
271  array_unique 
272 --------------
273  {1,4,12,16}
274 (1 row)
275
276 SELECT array_unique('{12,12,1,4,1,16}'::text[]);
277  array_unique 
278 --------------
279  {1,12,16,4}
280 (1 row)
281
282 SELECT array_unique('{12,12,1,4,1,16}'::varchar[]);
283  array_unique 
284 --------------
285  {1,12,16,4}
286 (1 row)
287
288 SELECT inarray('{12,12,1,4,1,16}'::int[], 13::int);
289  inarray 
290 ---------
291        0
292 (1 row)
293
294 SELECT inarray('{12,12,1,4,1,16}'::int[], 12::int);
295  inarray 
296 ---------
297        1
298 (1 row)
299
300 SELECT inarray('{12,12,1,4,1,16}'::text[], 13::text);
301  inarray 
302 ---------
303        0
304 (1 row)
305
306 SELECT inarray('{12,12,1,4,1,16}'::text[], 12::text);
307  inarray 
308 ---------
309        1
310 (1 row)
311
312 SELECT inarray('{12,12,1,4,1,16}'::int[], 13::int, 0.9, 0.1);
313  inarray 
314 ---------
315      0.1
316 (1 row)
317
318 SELECT inarray('{12,12,1,4,1,16}'::int[], 12::int, 0.9, 0.1);
319  inarray 
320 ---------
321      0.9
322 (1 row)
323
324 SELECT inarray('{12,12,1,4,1,16}'::text[], 13::text, 0.9, 0.1);
325  inarray 
326 ---------
327      0.1
328 (1 row)
329
330 SELECT inarray('{12,12,1,4,1,16}'::text[], 12::text, 0.9, 0.1);
331  inarray 
332 ---------
333      0.9
334 (1 row)
335
336 --testing function
337 CREATE OR REPLACE FUNCTION epoch2timestamp(int4)
338 RETURNS timestamp AS $$
339     SELECT ('1970-01-01 00:00:00'::timestamp +   ( ($1*3600*24 + $1) ::text || ' seconds' )::interval)::timestamp;
340         $$ LANGUAGE SQL RETURNS NULL ON NULL INPUT IMMUTABLE;
341 CREATE OR REPLACE FUNCTION to_tsp_array(_int4)
342 RETURNS _timestamp AS $$
343         SELECT ARRAY( 
344                 SELECT 
345                         epoch2timestamp( $1[n] )
346                 FROM
347                         generate_series( 1, array_upper( $1, 1) - array_lower( $1, 1 ) + 1 ) AS n
348         );
349         $$ LANGUAGE SQL RETURNS NULL ON NULL INPUT IMMUTABLE;
350 CREATE OR REPLACE FUNCTION array_to_col(anyarray)
351 RETURNS SETOF anyelement AS
352 $$
353     SELECT $1[n] FROM generate_series( 1, array_upper( $1, 1) - array_lower( $1, 1 ) + 1 ) AS n;
354 $$ LANGUAGE SQL RETURNS NULL ON NULL INPUT IMMUTABLE;