 			-- do nothing
 	END;
 	RETURN coalesce(r,0);
-END;
-$$ LANGUAGE plpgsql IMMUTABLE CALLED ON NULL INPUT;
-CREATE OR REPLACE FUNCTION str2inet (a text) RETURNS inet AS $$
-DECLARE
-	r inet;
-BEGIN
-	BEGIN
-		SELECT INTO r a::inet;
-	EXCEPTION
-		WHEN OTHERS THEN
-			-- do nothing
-	END;
-	RETURN r;
 END;
 $$ LANGUAGE plpgsql IMMUTABLE CALLED ON NULL INPUT;
 CREATE OR REPLACE FUNCTION str2time (a text) RETURNS timestamp AS $$

$$ LANGUAGE sql IMMUTABLE STRICT;

----------------------------
-- GET OBJECT CLASS/STATE
----------------------------
CREATE OR REPLACE FUNCTION obj_class_id (a_obj_id integer) RETURNS integer AS $$
	SELECT class_id FROM obj WHERE obj_id = $1;
$$ LANGUAGE sql IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION obj_class (a_obj_id integer) RETURNS text AS $$
	SELECT name FROM ref WHERE obj_id=(SELECT class_id FROM obj WHERE obj_id=$1);
$$ LANGUAGE sql STABLE STRICT;
CREATE OR REPLACE FUNCTION get_object_state_id (a_obj_id integer) RETURNS integer AS $$
DECLARE
	res integer;
BEGIN

CREATE OR REPLACE FUNCTION cjoin (a_strs text[],a_delimiter text) RETURNS text AS $$
	SELECT array_to_string($1,$2);
$$ LANGUAGE sql IMMUTABLE STRICT;

--- STRING functions
CREATE OR REPLACE FUNCTION collapse_spaces (a text) RETURNS text AS $$
    SELECT regexp_replace($1,E'\\s+',' ','g');
$$ LANGUAGE sql IMMUTABLE CALLED ON NULL INPUT;

-- LANG
CREATE OR REPLACE FUNCTION unlang (a_str text) RETURNS text AS $$
