CREATE OR REPLACE FUNCTION field(value TEXT, VARIADIC arr TEXT[])
RETURNS INT AS $$
DECLARE
i INT;
BEGIN
FOR i IN 1 .. array_length(arr, 1) LOOP
IF arr[i] = value THEN
RETURN i;
END IF;
END LOOP;
RETURN 0;
END;
$$ LANGUAGE plpgsql IMMUTABLE;