v13 support
[smlar.git] / expected / smlar.out
1 CREATE EXTENSION smlar;
2 set extra_float_digits =0;
3 --sanity check
4 SELECT 
5         opc.opcname, 
6         t.typname, 
7         opc.opcdefault  
8 FROM 
9         pg_opclass opc, 
10         pg_am am, 
11         pg_type t, 
12         pg_type k 
13 WHERE 
14         opc.opcmethod = am.oid AND 
15         am.amname='gist' AND 
16         opc.opcintype = t.oid AND 
17         opc.opckeytype = k.oid AND 
18         k.typname='gsmlsign'
19 ORDER BY opc.opcname;
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
42 (20 rows)
43
44 SELECT 
45         opc.opcname, 
46         t.typname, 
47         opc.opcdefault  
48 FROM 
49         pg_opclass opc, 
50         pg_am am, 
51         pg_type t
52 WHERE 
53         opc.opcmethod = am.oid AND 
54         am.amname='gin' AND 
55         opc.opcintype = t.oid AND 
56         opc.opcname ~ '_sml_ops$'
57 ORDER BY opc.opcname;
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
83 (23 rows)
84
85 SELECT 
86     trim( leading '_'  from t.typname ) || '[]' AS "Array Type",
87     gin.opcname AS "GIN operator class",
88     gist.opcname AS "GiST operator class"
89 FROM
90     (
91         SELECT *
92         FROM
93             pg_catalog.pg_opclass,
94             pg_catalog.pg_am
95         WHERE
96             pg_opclass.opcmethod = pg_am.oid AND
97             pg_am.amname = 'gin' AND
98             pg_opclass.opcname ~ '_sml_ops$'
99     ) AS gin
100     FULL OUTER JOIN
101         (
102             SELECT *
103             FROM
104                 pg_catalog.pg_opclass,
105                 pg_catalog.pg_am
106             WHERE
107                 pg_opclass.opcmethod = pg_am.oid AND
108                 pg_am.amname = 'gist' AND
109                 pg_opclass.opcname ~ '_sml_ops$'
110         ) AS gist
111         ON (
112             gist.opcname = gin.opcname AND 
113             gist.opcintype = gin.opcintype 
114         ),
115     pg_catalog.pg_type t
116 WHERE
117     t.oid = COALESCE(gist.opcintype, gin.opcintype) AND
118     t.typarray = 0
119 ORDER BY
120     "Array Type" ASC 
121 ;
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
147 (23 rows)
148
149 SELECT set_smlar_limit(0.1);
150  set_smlar_limit 
151 -----------------
152              0.1
153 (1 row)
154
155 SET smlar.threshold = 0.6;
156 --First checks
157 SELECT smlar('{3,2}'::int[], '{3,2,1}');
158   smlar   
159 ----------
160  0.816497
161 (1 row)
162
163 SELECT smlar('{2,1}'::int[], '{3,2,1}');
164   smlar   
165 ----------
166  0.816497
167 (1 row)
168
169 SELECT smlar('{}'::int[], '{3,2,1}');
170  smlar 
171 -------
172      0
173 (1 row)
174
175 SELECT smlar('{12,10}'::int[], '{3,2,1}');
176  smlar 
177 -------
178      0
179 (1 row)
180
181 SELECT smlar('{123}'::int[], '{}');
182  smlar 
183 -------
184      0
185 (1 row)
186
187 SELECT smlar('{1,4,6}'::int[], '{1,4,6}');
188  smlar 
189 -------
190      1
191 (1 row)
192
193 SELECT smlar('{1,4,6}'::int[], '{6,4,1}');
194  smlar 
195 -------
196      1
197 (1 row)
198
199 SELECT smlar('{1,4,6}'::int[], '{5,4,6}');
200   smlar   
201 ----------
202  0.666667
203 (1 row)
204
205 SELECT smlar('{1,4,6}'::int[], '{5,4,6}');
206   smlar   
207 ----------
208  0.666667
209 (1 row)
210
211 SELECT smlar('{1,2}'::int[], '{2,2,2,2,2,1}');
212  smlar 
213 -------
214      1
215 (1 row)
216
217 SELECT smlar('{1,2}'::int[], '{1,2,2,2,2,2}');
218  smlar 
219 -------
220      1
221 (1 row)
222
223 SELECT smlar('{}'::int[], '{3}');
224  smlar 
225 -------
226      0
227 (1 row)
228
229 SELECT smlar('{3}'::int[], '{3}');
230  smlar 
231 -------
232      1
233 (1 row)
234
235 SELECT smlar('{2}'::int[], '{3}');
236  smlar 
237 -------
238      0
239 (1 row)
240
241 SELECT smlar('{1,4,6}'::int[], '{5,4,6}', 'N.i / (N.a + N.b)' );
242   smlar   
243 ----------
244  0.333333
245 (1 row)
246
247 SELECT smlar('{1,4,6}'::int[], '{5,4,6}', 'N.i / sqrt(N.a * N.b)' );
248   smlar   
249 ----------
250  0.666667
251 (1 row)
252
253 SELECT tsvector2textarray('qwe:12 asd:45');
254  tsvector2textarray 
255 --------------------
256  {asd,qwe}
257 (1 row)
258
259 SELECT array_unique('{12,12,1,4,1,16}'::int4[]);
260  array_unique 
261 --------------
262  {1,4,12,16}
263 (1 row)
264
265 SELECT array_unique('{12,12,1,4,1,16}'::bigint[]);
266  array_unique 
267 --------------
268  {1,4,12,16}
269 (1 row)
270
271 SELECT array_unique('{12,12,1,4,1,16}'::smallint[]);
272  array_unique 
273 --------------
274  {1,4,12,16}
275 (1 row)
276
277 SELECT array_unique('{12,12,1,4,1,16}'::text[]);
278  array_unique 
279 --------------
280  {1,12,16,4}
281 (1 row)
282
283 SELECT array_unique('{12,12,1,4,1,16}'::varchar[]);
284  array_unique 
285 --------------
286  {1,12,16,4}
287 (1 row)
288
289 SELECT inarray('{12,12,1,4,1,16}'::int[], 13::int);
290  inarray 
291 ---------
292        0
293 (1 row)
294
295 SELECT inarray('{12,12,1,4,1,16}'::int[], 12::int);
296  inarray 
297 ---------
298        1
299 (1 row)
300
301 SELECT inarray('{12,12,1,4,1,16}'::text[], 13::text);
302  inarray 
303 ---------
304        0
305 (1 row)
306
307 SELECT inarray('{12,12,1,4,1,16}'::text[], 12::text);
308  inarray 
309 ---------
310        1
311 (1 row)
312
313 SELECT inarray('{12,12,1,4,1,16}'::int[], 13::int, 0.9, 0.1);
314  inarray 
315 ---------
316      0.1
317 (1 row)
318
319 SELECT inarray('{12,12,1,4,1,16}'::int[], 12::int, 0.9, 0.1);
320  inarray 
321 ---------
322      0.9
323 (1 row)
324
325 SELECT inarray('{12,12,1,4,1,16}'::text[], 13::text, 0.9, 0.1);
326  inarray 
327 ---------
328      0.1
329 (1 row)
330
331 SELECT inarray('{12,12,1,4,1,16}'::text[], 12::text, 0.9, 0.1);
332  inarray 
333 ---------
334      0.9
335 (1 row)
336
337 --testing function
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 $$
344         SELECT ARRAY( 
345                 SELECT 
346                         epoch2timestamp( $1[n] )
347                 FROM
348                         generate_series( 1, array_upper( $1, 1) - array_lower( $1, 1 ) + 1 ) AS n
349         );
350         $$ LANGUAGE SQL RETURNS NULL ON NULL INPUT IMMUTABLE;
351 CREATE OR REPLACE FUNCTION array_to_col(anyarray)
352 RETURNS SETOF anyelement AS
353 $$
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;