ClickHouse function reference

aggThrow

Throws an exception with a specified probability. This function is primarily used for testing exception handling and safety in ClickHouse.

Syntax:

aggThrow(throw_prob)

Arguments:

  • throw_prob (Float64): The probability of throwing an exception. Value should be between 0 and 1.

Returns:

This function doesn’t return a value. Instead, it throws an exception with the following message:

Code: 503. DB::Exception: Aggregate function aggThrow has thrown exception successfully.

Example:

SELECT
	taco_type,
	aggThrow(0.5) AS risky_taco_count
FROM
(
    SELECT 'Beef' AS taco_type
    UNION ALL
    SELECT 'Chicken' AS taco_type
    UNION ALL
    SELECT 'Vegetarian' AS taco_type
) AS taco_orders
GROUP BY
	taco_type;

This query attempts to count tacos by type, but has a 50% chance of throwing an exception for each group. If an exception is thrown, you might see:

Received exception: Code: 503. DB::Exception: Aggregate function aggThrow has thrown exception successfully: While executing AggregatingTransform. (AGGREGATE_FUNCTION_THROW)

This function is not intended for use in production environments. It’s designed for testing how your system handles exceptions in aggregate functions.