Commits

Tuukka Norri  committed 85fee77

Custom operators
- The custom <> operator should now work even with arrays.
- Removed HASHES qualifiers from operators, since they don't actually meet the requirements.

  • Participants
  • Parent commits a7b0aed

Comments (0)

Files changed (1)

File Resources/BaseTenModifications.sql.m4

 neq_function({{polygon}});
 
 
-define({{neq_function}}, {{
-CREATE FUNCTION "baseten".neq ($1, $1) RETURNS BOOLEAN AS $$
-	SELECT ${{}}1 <> ${{}}2;
+CREATE FUNCTION "baseten".neq (anynonarray, anynonarray) RETURNS BOOLEAN AS $$
+	SELECT $1 <> $2;
 $$ IMMUTABLE STRICT LANGUAGE SQL;
-REVOKE ALL PRIVILEGES ON FUNCTION "baseten".neq ($1, $1) FROM PUBLIC;
-GRANT EXECUTE ON FUNCTION "baseten".neq ($1, $1) TO basetenread
-}})dnl
-neq_function({{anyelement}});
-neq_function({{anyarray}});
+REVOKE ALL PRIVILEGES ON FUNCTION "baseten".neq (anynonarray, anynonarray) FROM PUBLIC;
+GRANT EXECUTE ON FUNCTION "baseten".neq (anynonarray, anynonarray) TO basetenread;
+
+
+CREATE FUNCTION "baseten".neq (anyarray, anyarray) RETURNS BOOLEAN AS $$
+BEGIN
+	IF array_ndims ($1) <> array_ndims ($2) THEN
+		RETURN true;
+	END IF;
+	
+	IF array_upper ($1, 1) <> array_upper ($2, 1) THEN
+		RETURN true;
+	END IF;
+	
+	FOR i IN 0..array_upper ($1, 1) LOOP
+		IF $1 [i] OPERATOR ("baseten".<>) $2 [i] THEN
+			RETURN true;
+		END IF;
+	END LOOP;
+	
+	RETURN false;
+END;
+$$ IMMUTABLE STRICT LANGUAGE PLPGSQL;
+REVOKE ALL PRIVILEGES ON FUNCTION "baseten".neq (anyarray, anyarray) FROM PUBLIC;
+GRANT EXECUTE ON FUNCTION "baseten".neq (anyarray, anyarray) TO basetenread;
 
 
 define({{neq_operator}}, {{
 	PROCEDURE = "baseten".neq,
 	LEFTARG = $1,
 	RIGHTARG = $1,
-	HASHES
+	COMMUTATOR = OPERATOR ("baseten".<>)
 )}})dnl
 neq_operator({{box}});
 neq_operator({{path}});
 neq_operator({{polygon}});
-neq_operator({{anyelement}});
+neq_operator({{anynonarray}});
 neq_operator({{anyarray}});
 
 
 REVOKE ALL PRIVILEGES ON FUNCTION "baseten".same ($1, $1) FROM PUBLIC;
 GRANT EXECUTE ON FUNCTION "baseten".same ($1, $1) TO basetenread
 }})dnl
-same_function({{anyelement}});
+same_function({{anynonarray}});
 same_function({{anyarray}});
 
 
 CREATE OPERATOR "baseten".<<>> (
 	PROCEDURE = "baseten".between,
 	LEFTARG = $1[2],
-	RIGHTARG = $1,
-	HASHES
+	RIGHTARG = $1
 )}})dnl
 between_operator({{SMALLINT}});
 between_operator({{INTEGER}});