1 CREATE EXTENSION smlar;
2 set extra_float_digits =0;
15 opc.opcmethod = am.oid AND
17 opc.opcintype = t.oid AND
18 opc.opckeytype = k.oid AND
31 opc.opcmethod = am.oid AND
33 opc.opcintype = t.oid AND
34 opc.opcname ~ '_sml_ops$'
38 trim( leading '_' from t.typname ) || '[]' AS "Array Type",
39 gin.opcname AS "GIN operator class",
40 gist.opcname AS "GiST operator class"
45 pg_catalog.pg_opclass,
48 pg_opclass.opcmethod = pg_am.oid AND
49 pg_am.amname = 'gin' AND
50 pg_opclass.opcname ~ '_sml_ops$'
56 pg_catalog.pg_opclass,
59 pg_opclass.opcmethod = pg_am.oid AND
60 pg_am.amname = 'gist' AND
61 pg_opclass.opcname ~ '_sml_ops$'
64 gist.opcname = gin.opcname AND
65 gist.opcintype = gin.opcintype
69 t.oid = COALESCE(gist.opcintype, gin.opcintype) AND
75 SELECT set_smlar_limit(0.1);
76 SET smlar.threshold = 0.6;
79 SELECT smlar('{3,2}'::int[], '{3,2,1}');
80 SELECT smlar('{2,1}'::int[], '{3,2,1}');
81 SELECT smlar('{}'::int[], '{3,2,1}');
82 SELECT smlar('{12,10}'::int[], '{3,2,1}');
83 SELECT smlar('{123}'::int[], '{}');
84 SELECT smlar('{1,4,6}'::int[], '{1,4,6}');
85 SELECT smlar('{1,4,6}'::int[], '{6,4,1}');
86 SELECT smlar('{1,4,6}'::int[], '{5,4,6}');
87 SELECT smlar('{1,4,6}'::int[], '{5,4,6}');
88 SELECT smlar('{1,2}'::int[], '{2,2,2,2,2,1}');
89 SELECT smlar('{1,2}'::int[], '{1,2,2,2,2,2}');
90 SELECT smlar('{}'::int[], '{3}');
91 SELECT smlar('{3}'::int[], '{3}');
92 SELECT smlar('{2}'::int[], '{3}');
95 SELECT smlar('{1,4,6}'::int[], '{5,4,6}', 'N.i / (N.a + N.b)' );
96 SELECT smlar('{1,4,6}'::int[], '{5,4,6}', 'N.i / sqrt(N.a * N.b)' );
98 SELECT tsvector2textarray('qwe:12 asd:45');
100 SELECT array_unique('{12,12,1,4,1,16}'::int4[]);
101 SELECT array_unique('{12,12,1,4,1,16}'::bigint[]);
102 SELECT array_unique('{12,12,1,4,1,16}'::smallint[]);
103 SELECT array_unique('{12,12,1,4,1,16}'::text[]);
104 SELECT array_unique('{12,12,1,4,1,16}'::varchar[]);
106 SELECT inarray('{12,12,1,4,1,16}'::int[], 13::int);
107 SELECT inarray('{12,12,1,4,1,16}'::int[], 12::int);
108 SELECT inarray('{12,12,1,4,1,16}'::text[], 13::text);
109 SELECT inarray('{12,12,1,4,1,16}'::text[], 12::text);
110 SELECT inarray('{12,12,1,4,1,16}'::int[], 13::int, 0.9, 0.1);
111 SELECT inarray('{12,12,1,4,1,16}'::int[], 12::int, 0.9, 0.1);
112 SELECT inarray('{12,12,1,4,1,16}'::text[], 13::text, 0.9, 0.1);
113 SELECT inarray('{12,12,1,4,1,16}'::text[], 12::text, 0.9, 0.1);
116 CREATE OR REPLACE FUNCTION epoch2timestamp(int4)
117 RETURNS timestamp AS $$
118 SELECT ('1970-01-01 00:00:00'::timestamp + ( ($1*3600*24 + $1) ::text || ' seconds' )::interval)::timestamp;
119 $$ LANGUAGE SQL RETURNS NULL ON NULL INPUT IMMUTABLE;
121 CREATE OR REPLACE FUNCTION to_tsp_array(_int4)
122 RETURNS _timestamp AS $$
125 epoch2timestamp( $1[n] )
127 generate_series( 1, array_upper( $1, 1) - array_lower( $1, 1 ) + 1 ) AS n
129 $$ LANGUAGE SQL RETURNS NULL ON NULL INPUT IMMUTABLE;
131 CREATE OR REPLACE FUNCTION array_to_col(anyarray)
132 RETURNS SETOF anyelement AS
134 SELECT $1[n] FROM generate_series( 1, array_upper( $1, 1) - array_lower( $1, 1 ) + 1 ) AS n;
135 $$ LANGUAGE SQL RETURNS NULL ON NULL INPUT IMMUTABLE;