-- SQL code to define the new array iterator functions and operators

-- define the array operators *=, **=, *~ and **~ for type _text
--

-- Adjust this setting to control where the objects get created.
SET search_path = public;

SET autocommit TO 'on';

CREATE OR REPLACE FUNCTION array_texteq(_text, text)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_all_texteq(_text, text)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_textregexeq(_text, text)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_all_textregexeq(_text, text)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OPERATOR *= (
	LEFTARG=_text, 
	RIGHTARG=text, 
	PROCEDURE=array_texteq
);

CREATE OPERATOR **= (
	LEFTARG=_text,
	RIGHTARG=text,
	PROCEDURE=array_all_texteq
);

CREATE OPERATOR *~ (
	LEFTARG=_text,
	RIGHTARG=text,
	PROCEDURE=array_textregexeq
);

CREATE OPERATOR **~ (
	LEFTARG=_text,
	RIGHTARG=text,
	PROCEDURE=array_all_textregexeq
);


-- define the array operators *=, **=, *~ and **~ for type _varchar
--
-- NOTE: "varchar" is also a reserved word and must be quoted.
--
CREATE OR REPLACE FUNCTION array_varchareq(_varchar, varchar)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_all_varchareq(_varchar, varchar)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_varcharregexeq(_varchar, varchar)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_all_varcharregexeq(_varchar, varchar)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OPERATOR *= (
	LEFTARG=_varchar, 
	RIGHTARG="varchar", 
	PROCEDURE=array_varchareq
);

CREATE OPERATOR **= (
	LEFTARG=_varchar,
	RIGHTARG="varchar",
	PROCEDURE=array_all_varchareq
);

CREATE OPERATOR *~ (
	LEFTARG=_varchar,
	RIGHTARG="varchar",
	PROCEDURE=array_varcharregexeq
);

CREATE OPERATOR **~ (
	LEFTARG=_varchar,
	RIGHTARG="varchar",
	PROCEDURE=array_all_varcharregexeq
);


-- define the array operators *=, **=, *~ and **~ for type _bpchar
--
CREATE OR REPLACE FUNCTION array_bpchareq(_bpchar, bpchar)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_all_bpchareq(_bpchar, bpchar)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_bpcharregexeq(_bpchar, bpchar)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_all_bpcharregexeq(_bpchar, bpchar)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OPERATOR *= (
	LEFTARG=_bpchar, 
	RIGHTARG=bpchar, 
	PROCEDURE=array_bpchareq
);

CREATE OPERATOR **= (
	LEFTARG=_bpchar,
	RIGHTARG=bpchar,
	PROCEDURE=array_all_bpchareq
);

CREATE OPERATOR *~ (
	LEFTARG=_bpchar,
	RIGHTARG=bpchar,
	PROCEDURE=array_bpcharregexeq
);

CREATE OPERATOR **~ (
	LEFTARG=_bpchar,
	RIGHTARG=bpchar,
	PROCEDURE=array_all_bpcharregexeq
);


-- define the array operators *=, **=, *> and **> for type _int4
--
CREATE OR REPLACE FUNCTION array_int4eq(_int4, int4)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_all_int4eq(_int4, int4)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_int4ne(_int4, int4)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_all_int4ne(_int4, int4)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_int4gt(_int4, int4)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_all_int4gt(_int4, int4)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_int4ge(_int4, int4)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_all_int4ge(_int4, int4)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_int4lt(_int4, int4)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_all_int4lt(_int4, int4)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_int4le(_int4, int4)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_all_int4le(_int4, int4)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OPERATOR *= (
	LEFTARG=_int4,
	RIGHTARG=int4,
	PROCEDURE=array_int4eq
);

CREATE OPERATOR **= (
	LEFTARG=_int4,
	RIGHTARG=int4,
	PROCEDURE=array_all_int4eq
);

CREATE OPERATOR *<> (
	LEFTARG=_int4,
	RIGHTARG=int4,
	PROCEDURE=array_int4ne
);

CREATE OPERATOR **<> (
	LEFTARG=_int4,
	RIGHTARG=int4,
	PROCEDURE=array_all_int4ne
);

CREATE OPERATOR *> (
	LEFTARG=_int4,
	RIGHTARG=int4,
	PROCEDURE=array_int4gt
);

CREATE OPERATOR **> (
	LEFTARG=_int4,
	RIGHTARG=int4,
	PROCEDURE=array_all_int4gt
);

CREATE OPERATOR *>= (
	LEFTARG=_int4,
	RIGHTARG=int4,
	PROCEDURE=array_int4ge
);

CREATE OPERATOR **>= (
	LEFTARG=_int4,
	RIGHTARG=int4,
	PROCEDURE=array_all_int4ge
);

CREATE OPERATOR *< (
	LEFTARG=_int4,
	RIGHTARG=int4,
	PROCEDURE=array_int4lt
);

CREATE OPERATOR **< (
	LEFTARG=_int4,
	RIGHTARG=int4,
	PROCEDURE=array_all_int4lt
);

CREATE OPERATOR *<= (
	LEFTARG=_int4,
	RIGHTARG=int4,
	PROCEDURE=array_int4le
);

CREATE OPERATOR **<= (
	LEFTARG=_int4,
	RIGHTARG=int4,
	PROCEDURE=array_all_int4le
);

-- define the array operators *=, **<>  for type _oid  (added tobias 1. 1999)
--
CREATE OR REPLACE FUNCTION array_oideq(_oid, oid)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_all_oidne(_oid, oid)
RETURNS bool
AS 'MODULE_PATHNAME' 
LANGUAGE 'C' WITH (isStrict);

CREATE OPERATOR *= (
	LEFTARG=_oid, 
	RIGHTARG=oid, 
	PROCEDURE=array_oideq
);

CREATE OPERATOR **<> (
	LEFTARG=_oid,
	RIGHTARG=oid,
	PROCEDURE=array_all_oidne
);

-- define the array operators *=, **=, *<>, **<> for type _inet

CREATE OR REPLACE FUNCTION array_ineteq(_inet, inet)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_all_ineteq(_inet, inet)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_inetne(_inet, inet)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE 'C' WITH (isStrict);

CREATE OR REPLACE FUNCTION array_all_inetne(_inet, inet)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE 'C' WITH (isStrict);

CREATE OPERATOR *= (
	LEFTARG=_inet,
	RIGHTARG=inet,
	PROCEDURE=array_ineteq
);

CREATE OPERATOR **= (
	LEFTARG=_inet,
	RIGHTARG=inet,
	PROCEDURE=array_all_ineteq
);

CREATE OPERATOR *<> (
	LEFTARG=_inet,
	RIGHTARG=inet,
	PROCEDURE=array_inetne
);

CREATE OPERATOR **<> (
	LEFTARG=_inet,
	RIGHTARG=inet,
	PROCEDURE=array_all_inetne
);
