Example: my_bit_or Declaration

The “my_bit_or” example is similar to the SA built-in BIT_OR except it operates only on unsigned integers and can be used only as a simple aggregate.

my_bit_or declaration

The resulting declaration looks like:

CREATE AGGREGATE FUNCTION my_bit_or(IN arg1 UNSIGNED INT) 
	 RETURNS UNSIGNED INT
	 ON EMPTY INPUT RETURNS NULL
	 OVER NOT ALLOWED
	 EXTERNAL NAME 'describe_my_bit_or@ my_shared_lib'

Unlike the my_bit_xor example, the OVER NOT ALLOWED phrase in the declaration restricts the use of this function to a simple aggregate. Because of that usage restriction, my_bit_or is only usable as a simple aggregate across an entire set of rows, or as a simple aggregate computed for each group as specified by a GROUP BY clause shown in the following example:

SELECT t.x, COUNT(*), my_bit_or(t.y)
FROM t
GROUP BY t.x