1 CREATE EXTENSION smlar;
14 opc.opcmethod = am.oid AND
16 opc.opcintype = t.oid AND
17 opc.opckeytype = k.oid AND
30 opc.opcmethod = am.oid AND
32 opc.opcintype = t.oid AND
33 opc.opcname ~ '_sml_ops$'
37 trim( leading '_' from t.typname ) || '[]' AS "Array Type",
38 gin.opcname AS "GIN operator class",
39 gist.opcname AS "GiST operator class"
44 pg_catalog.pg_opclass,
47 pg_opclass.opcmethod = pg_am.oid AND
48 pg_am.amname = 'gin' AND
49 pg_opclass.opcname ~ '_sml_ops$'
55 pg_catalog.pg_opclass,
58 pg_opclass.opcmethod = pg_am.oid AND
59 pg_am.amname = 'gist' AND
60 pg_opclass.opcname ~ '_sml_ops$'
63 gist.opcname = gin.opcname AND
64 gist.opcintype = gin.opcintype
68 t.oid = COALESCE(gist.opcintype, gin.opcintype) AND
74 SELECT set_smlar_limit(0.1);
75 SET smlar.threshold = 0.6;
78 SELECT smlar('{3,2}'::int[], '{3,2,1}');
79 SELECT smlar('{2,1}'::int[], '{3,2,1}');
80 SELECT smlar('{}'::int[], '{3,2,1}');
81 SELECT smlar('{12,10}'::int[], '{3,2,1}');
82 SELECT smlar('{123}'::int[], '{}');
83 SELECT smlar('{1,4,6}'::int[], '{1,4,6}');
84 SELECT smlar('{1,4,6}'::int[], '{6,4,1}');
85 SELECT smlar('{1,4,6}'::int[], '{5,4,6}');
86 SELECT smlar('{1,4,6}'::int[], '{5,4,6}');
87 SELECT smlar('{1,2}'::int[], '{2,2,2,2,2,1}');
88 SELECT smlar('{1,2}'::int[], '{1,2,2,2,2,2}');
89 SELECT smlar('{}'::int[], '{3}');
90 SELECT smlar('{3}'::int[], '{3}');
91 SELECT smlar('{2}'::int[], '{3}');
94 SELECT smlar('{1,4,6}'::int[], '{5,4,6}', 'N.i / (N.a + N.b)' );
95 SELECT smlar('{1,4,6}'::int[], '{5,4,6}', 'N.i / sqrt(N.a * N.b)' );
97 SELECT tsvector2textarray('qwe:12 asd:45');
99 SELECT array_unique('{12,12,1,4,1,16}'::int4[]);
100 SELECT array_unique('{12,12,1,4,1,16}'::bigint[]);
101 SELECT array_unique('{12,12,1,4,1,16}'::smallint[]);
102 SELECT array_unique('{12,12,1,4,1,16}'::text[]);
103 SELECT array_unique('{12,12,1,4,1,16}'::varchar[]);
105 SELECT inarray('{12,12,1,4,1,16}'::int[], 13::int);
106 SELECT inarray('{12,12,1,4,1,16}'::int[], 12::int);
107 SELECT inarray('{12,12,1,4,1,16}'::text[], 13::text);
108 SELECT inarray('{12,12,1,4,1,16}'::text[], 12::text);
109 SELECT inarray('{12,12,1,4,1,16}'::int[], 13::int, 0.9, 0.1);
110 SELECT inarray('{12,12,1,4,1,16}'::int[], 12::int, 0.9, 0.1);
111 SELECT inarray('{12,12,1,4,1,16}'::text[], 13::text, 0.9, 0.1);
112 SELECT inarray('{12,12,1,4,1,16}'::text[], 12::text, 0.9, 0.1);
115 CREATE OR REPLACE FUNCTION epoch2timestamp(int4)
116 RETURNS timestamp AS $$
117 SELECT ('1970-01-01 00:00:00'::timestamp + ( ($1*3600*24 + $1) ::text || ' seconds' )::interval)::timestamp;
118 $$ LANGUAGE SQL RETURNS NULL ON NULL INPUT IMMUTABLE;
120 CREATE OR REPLACE FUNCTION to_tsp_array(_int4)
121 RETURNS _timestamp AS $$
124 epoch2timestamp( $1[n] )
126 generate_series( 1, array_upper( $1, 1) - array_lower( $1, 1 ) + 1 ) AS n
128 $$ LANGUAGE SQL RETURNS NULL ON NULL INPUT IMMUTABLE;
130 CREATE OR REPLACE FUNCTION array_to_col(anyarray)
131 RETURNS SETOF anyelement AS
133 SELECT $1[n] FROM generate_series( 1, array_upper( $1, 1) - array_lower( $1, 1 ) + 1 ) AS n;
134 $$ LANGUAGE SQL RETURNS NULL ON NULL INPUT IMMUTABLE;