-----------------------------------------------------------
-- install the in_record type
-----------------------------------------------------------
create function inr_in(opaque) 
	RETURNS inrecord
	AS '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
	
create function inr_out(opaque)
	RETURNS opaque
	AS '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';

create type inrecord (
	internallength=VARIABLE,
	input=inr_in,
	output=inr_out
);

-----------------------------------------------------------
-- return type as text
create function inr_type(inrecord)
	returns bpchar
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
-- or number
create function inr_nr(inrecord)
	returns int
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
-----------------------------------------------------------
--
-- return record as text
--
create function inr_data(inrecord)
	returns text
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
--
-- inr_inet:
-- 	return address record as inet
--	drops error on text record
create function inr_inet(inrecord)
	returns inet
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
-----------------------------------------------------------
--
-- comparision functions
--	inrecord,inrecord
create function inr_cmp(inrecord,inrecord)
	returns int4
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inr_lt(inrecord,inrecord)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inr_le(inrecord,inrecord)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inr_eq(inrecord,inrecord)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inr_ge(inrecord,inrecord)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inr_gt(inrecord,inrecord)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inr_ne(inrecord,inrecord)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';

--
-- comparision operators
--	inrecord,inrecord
create operator < (
	procedure=inr_lt,
	leftarg=inrecord,
	rightarg=inrecord,
	commutator= <,
	negator= >=
);
create operator <= (
	procedure=inr_le,
	leftarg=inrecord,
	rightarg=inrecord,
	commutator= <=,
	negator= >
);
create operator = (
	procedure=inr_eq,
	leftarg=inrecord,
	rightarg=inrecord,
	commutator= '=',
	negator= '!=',
	restrict = eqsel,
	join = eqjoinsel,
	HASHES
);
create operator >= (
	procedure=inr_ge,
	leftarg=inrecord,
	rightarg=inrecord,
	commutator= =,
	negator= <
);
create operator > (
	procedure=inr_gt,
	leftarg=inrecord,
	rightarg=inrecord,
	commutator= >,
	negator= <=
);
create operator != (
	procedure=inr_ne,
	leftarg=inrecord,
	rightarg=inrecord,
	commutator= '!=',
	negator= '=',
	restrict = neqsel,
	join = neqjoinsel,
	HASHES
);

-----------------------------------------------------------
--
-- comparision functions
--	inrecord,inet
--	inrinet_lt	<
--	inrinet_le	<=
--	inrinet_eq	=
--	inrinet_ge	>=
--	inrinet_gt	>
--	inrinet_sub	<<
--	inrinet_subeq	<<=
--	inrinet_sup	>>
--	inrinet_supeq	>>=

create function inrinet_lt(inrecord,inet)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inrinet_le(inrecord,inet)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inrinet_eq(inrecord,inet)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inrinet_ge(inrecord,inet)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inrinet_gt(inrecord,inet)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inrinet_ne(inrecord,inet)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inrinet_sub(inrecord,inet)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inrinet_subeq(inrecord,inet)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inrinet_sup(inrecord,inet)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inrinet_supeq(inrecord,inet)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';

--
-- comparision operators
--	inrecord,inrecord
create operator < (
	procedure=inrinet_lt,
	leftarg=inrecord,
	rightarg=inet,
	commutator= <,
	negator= >=
);
create operator <= (
	procedure=inrinet_le,
	leftarg=inrecord,
	rightarg=inet,
	commutator= <=,
	negator= >
);
create operator = (
	procedure=inrinet_eq,
	leftarg=inrecord,
	rightarg=inet,
	commutator= =,
	negator= !=
);
create operator >= (
	procedure=inrinet_ge,
	leftarg=inrecord,
	rightarg=inet,
	commutator= >=,
	negator= <
);
create operator > (
	procedure=inrinet_gt,
	leftarg=inrecord,
	rightarg=inet,
	commutator= >,
	negator= <=
);
create operator << (
	procedure=inrinet_sub,
	leftarg=inrecord,
	rightarg=inet,
	commutator= <<
);
create operator <<= (
	procedure=inrinet_subeq,
	leftarg=inrecord,
	rightarg=inet,
	commutator= <<=
);
create operator >> (
	procedure=inrinet_sup,
	leftarg=inrecord,
	rightarg=inet,
	commutator= >>
);
create operator >>= (
	procedure=inrinet_supeq,
	leftarg=inrecord,
	rightarg=inet,
	commutator= >>=
);
---------------------------------------
--
-- comparision functions for cnames
--	(case insensitive)
--	inrecord,inrecord
--		inr_like	~~
--		inr_nlike	!~~
--		inr_regexp	~
--		inr_nregexp	!~
--	inrecord,text
--		inrtext_like	~~
--		inrtext_nlike	!~~
--		inrtext_regexp	~
--		inrtext_nregexp	!~
create function inr_like(inrecord,inrecord)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inrtext_like(inrecord,text)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inrtext_like(inrecord,bpchar)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';

create function inr_nlike(inrecord,inrecord)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inrtext_nlike(inrecord,text)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inrtext_nlike(inrecord,bpchar)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';

create function inr_regexp(inrecord,inrecord)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inrtext_regexp(inrecord,text)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inrtext_regexp(inrecord,bpchar)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';

create function inr_nregexp(inrecord,inrecord)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inrtext_nregexp(inrecord,text)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
create function inrtext_nregexp(inrecord,bpchar)
	returns bool
	as '/home/drillich/src/dns/db/src/in_record.so' 
	Language 'C';
-- operators
create operator ~~ (
	procedure=inr_like,
	leftarg=inrecord,
	rightarg=inrecord,
	commutator= ~~,
	negator= !~~
);
create operator ~~ (
	procedure=inrtext_like,
	leftarg=inrecord,
	rightarg=text,
	commutator= ~~,
	negator= !~~
);
create operator ~~ (
	procedure=inrtext_like,
	leftarg=inrecord,
	rightarg=bpchar,
	commutator= ~~,
	negator= !~~
);
create operator !~~ (
	procedure=inr_nlike,
	leftarg=inrecord,
	rightarg=inrecord,
	commutator= ~~,
	negator= !~~
);
create operator !~~ (
	procedure=inrtext_nlike,
	leftarg=inrecord,
	rightarg=text,
	commutator= !~~,
	negator= ~~
);
create operator !~~ (
	procedure=inrtext_nlike,
	leftarg=inrecord,
	rightarg=bpchar,
	commutator= !~~,
	negator= ~~
);
create operator ~ (
	procedure=inr_regexp,
	leftarg=inrecord,
	rightarg=inrecord,
	commutator= ~,
	negator= !~
);
create operator ~ (
	procedure=inrtext_regexp,
	leftarg=inrecord,
	rightarg=text,
	commutator= ~,
	negator= !~
);
create operator ~ (
	procedure=inrtext_regexp,
	leftarg=inrecord,
	rightarg=bpchar,
	commutator= ~,
	negator= !~
);
create operator !~ (
	procedure=inr_nregexp,
	leftarg=inrecord,
	rightarg=inrecord,
	commutator= !~,
	negator= ~
);
create operator !~ (
	procedure=inrtext_nregexp,
	leftarg=inrecord,
	rightarg=text,
	commutator= !~,
	negator= ~
);
create operator !~ (
	procedure=inrtext_nregexp,
	leftarg=inrecord,
	rightarg=bpchar,
	commutator= !~,
	negator= ~
);
-- EOF in_record.sql
