 	END;
 END;
 $$ LANGUAGE plpgsql STABLE STRICT;
-CREATE OR REPLACE FUNCTION get_object_state (a_obj_id integer) RETURNS text AS $$
+CREATE OR REPLACE FUNCTION get_obj_state (a_obj_id integer) RETURNS text AS $$
 DECLARE
 	res text;
 BEGIN

			-- 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 STABLE CALLED ON NULL INPUT;
CREATE OR REPLACE FUNCTION prepare_replace (INOUT a_data replace_data,name text,value inet,old inet) AS $$
	SELECT	CASE WHEN $3 IS NULL THEN $1.keys ELSE coalesce($1.keys||',','')||$2 END,
		CASE WHEN $3 IS NULL THEN $1.vals ELSE coalesce($1.vals||',','')||quote_literal($3::text) END,
		CASE WHEN $3 IS NULL OR $3=$4 THEN $1.sets ELSE coalesce($1.sets||',','')||$2||'='||quote_literal($3::text) END;
$$ LANGUAGE sql STABLE CALLED ON NULL INPUT;

