CREATE or replace FUNCTION btint4rangecmp(int4, int4range) RETURNS int4 AS
$$
SELECT CASE WHEN $1 < lower($2) THEN -1
            WHEN $1 < upper($2) OR upper($2) IS NULL THEN 0
            ELSE 1 END
$$
LANGUAGE SQL IMMUTABLE STRICT;

CREATE FUNCTION int4_contained_by_int4range (int4, int4range) RETURNS bool AS
'elem_contained_by_range' LANGUAGE internal IMMUTABLE STRICT;

CREATE OPERATOR <@ (
  PROCEDURE=int4_contained_by_int4range,
  LEFTARG=int4, RIGHTARG=int4range
);

ALTER OPERATOR FAMILY integer_ops USING btree ADD
  OPERATOR 3 <@ (int4, int4range),
  FUNCTION 1 btint4rangecmp(int4, int4range);


-- Create a test table
create table inttable (i int4 primary key);
insert into inttable select g from generate_series(1,100000) g;

-- Query it. Uses index, hooray!
select * from inttable where i <@ int4range(111, 120);
