DROP OPERATOR & (INT2, INT2);
DROP OPERATOR | (INT2, INT2);
DROP OPERATOR ^ (INT2, INT2);
DROP OPERATOR ~ (NONE, INT2);
DROP OPERATOR & (INT4, INT4);
DROP OPERATOR | (INT4, INT4);
DROP OPERATOR ^ (INT4, INT4);
DROP OPERATOR ~ (NONE, INT4);

DROP FUNCTION am_int_bit_and(INT2, INT2);
DROP FUNCTION am_int_bit_or(INT2, INT2);
DROP FUNCTION am_int_bit_xor(INT2, INT2);
DROP FUNCTION am_int_bit_not(INT2);
DROP FUNCTION am_int_bit_and(INT4, INT4);
DROP FUNCTION am_int_bit_or(INT4, INT4);
DROP FUNCTION am_int_bit_xor(INT4, INT4);
DROP FUNCTION am_int_bit_not(INT4);

------------------------------------------------------------------------

CREATE FUNCTION am_int_bit_and(int2, int2) RETURNS int2
AS '/local/www/sites/odin/sql/int_bit_operators/am_int_bit_operators.so', 'am_int_bit_and'
LANGUAGE 'C';

CREATE FUNCTION am_int_bit_or(int2, int2) RETURNS int2
AS '/local/www/sites/odin/sql/int_bit_operators/am_int_bit_operators.so', 'am_int_bit_or'
LANGUAGE 'C';

CREATE FUNCTION am_int_bit_xor(int2, int2) RETURNS int2
AS '/local/www/sites/odin/sql/int_bit_operators/am_int_bit_operators.so', 'am_int_bit_xor'
LANGUAGE 'C';

CREATE FUNCTION am_int_bit_not(int2) RETURNS int2
AS '/local/www/sites/odin/sql/int_bit_operators/am_int_bit_operators.so', 'am_int_bit_not'
LANGUAGE 'C';

------------------------------------------------------------------------

CREATE OPERATOR & (
		LEFTARG = INT2,
		RIGHTARG = INT2,
		PROCEDURE = am_int_bit_and
		);

CREATE OPERATOR | (
		LEFTARG = INT2,
		RIGHTARG = INT2,
		PROCEDURE = am_int_bit_or
		);

CREATE OPERATOR ^ (
		LEFTARG = INT2,
		RIGHTARG = INT2,
		PROCEDURE = am_int_bit_xor
		);

CREATE OPERATOR ~ (
		RIGHTARG = INT2,
		PROCEDURE = am_int_bit_not
		);

-----------------------------------------------------------------

DROP AGGREGATE am_abitor INT2;
DROP AGGREGATE am_abitand INT2;
DROP AGGREGATE am_abitxor INT2;

DROP AGGREGATE am_abitor INT4;
DROP AGGREGATE am_abitand INT4;
DROP AGGREGATE am_abitxor INT4;

CREATE AGGREGATE am_abitor ( BASETYPE = INT2, SFUNC1 = am_int_bit_or, STYPE1 = INT2);
CREATE AGGREGATE am_abitand ( BASETYPE = INT2, SFUNC1 = am_int_bit_and, STYPE1 = INT2);
CREATE AGGREGATE am_abitxor ( BASETYPE = INT2, SFUNC1 = am_int_bit_xor, STYPE1 = INT2);

CREATE AGGREGATE am_abitor ( BASETYPE = INT4, SFUNC1 = am_int_bit_or, STYPE1 = INT4);
CREATE AGGREGATE am_abitand ( BASETYPE = INT4, SFUNC1 = am_int_bit_and, STYPE1 = INT4);
CREATE AGGREGATE am_abitxor ( BASETYPE = INT4, SFUNC1 = am_int_bit_xor, STYPE1 = INT4);








-----------------------------------------------------------------

CREATE FUNCTION am_int_bit_and(int4, int4) RETURNS int4
AS '/local/www/sites/odin/sql/int_bit_operators/am_int_bit_operators.so', 'am_int_bit_and'
LANGUAGE 'C';

CREATE FUNCTION am_int_bit_or(int4, int4) RETURNS int4
AS '/local/www/sites/odin/sql/int_bit_operators/am_int_bit_operators.so', 'am_int_bit_or'
LANGUAGE 'C';

CREATE FUNCTION am_int_bit_xor(int4, int4) RETURNS int4
AS '/local/www/sites/odin/sql/int_bit_operators/am_int_bit_operators.so', 'am_int_bit_xor'
LANGUAGE 'C';

CREATE FUNCTION am_int_bit_not(int4) RETURNS int4
AS '/local/www/sites/odin/sql/int_bit_operators/am_int_bit_operators.so', 'am_int_bit_not'
LANGUAGE 'C';

CREATE OPERATOR & (
		LEFTARG = INT4,
		RIGHTARG = INT4,
		PROCEDURE = am_int_bit_and
		);

CREATE OPERATOR | (
		LEFTARG = INT4,
		RIGHTARG = INT4,
		PROCEDURE = am_int_bit_or
		);

CREATE OPERATOR ^ (
		LEFTARG = INT4,
		RIGHTARG = INT4,
		PROCEDURE = am_int_bit_xor
		);

CREATE OPERATOR ~ (
		RIGHTARG = INT4,
		PROCEDURE = am_int_bit_not
		);
