CREATE OR replace function ks_db4.generate_subscripts(anyarray,int)

RETURNS SETOF int AS $$

begin

SELECT generate_series(array_lower($1,$2), array_upper($1,$2));

end

$$ LANGUAGE plpgsql;




CREATE OR REPLACE FUNCTION ks_db4.find_in_set(str integer, strlist text)

RETURNS boolean AS $$

SELECT i > 0

FROM generate_subscripts(string_to_array($2,','),1) g(i)

WHERE (string_to_array($2, ','))[i] = $1::text

$$ LANGUAGE sql STRICT;


CREATE OR REPLACE FUNCTION ks_db4.find_in_set(str bigint, strlist text)

RETURNS boolean AS $$

SELECT i > 0

FROM generate_subscripts(string_to_array($2,','),1) g(i)

WHERE (string_to_array($2, ','))[i] = $1::text

$$ LANGUAGE sql STRICT;



CREATE OR REPLACE FUNCTION ks_db4.find_in_set(str text, strlist text)

RETURNS boolean AS $$

SELECT i > 0

FROM generate_subscripts(string_to_array($2,','),1) g(i)

WHERE (string_to_array($2, ','))[i] = $1

$$ LANGUAGE sql STRICT;