private function prepareGeneratedFieldExpression($escaped_field_name, $escaped_expression, $caster, $escaped_default_value)
    {
        $value_extractor_expression = "{$escaped_field_name}->>{$escaped_expression}";

        switch ($caster) {
            case ValueCasterInterface::CAST_BOOL:
                return "IF({$value_extractor_expression} IS NULL, $escaped_default_value, IF({$value_extractor_expression} = 'true' OR ({$value_extractor_expression} REGEXP '^-?[0-9]+$' AND CAST({$value_extractor_expression} AS SIGNED) != 0), 1, 0))";
            case ValueCasterInterface::CAST_DATE:
                return "IF({$value_extractor_expression} IS NULL, $escaped_default_value, CAST({$value_extractor_expression} AS DATE))";
            case ValueCasterInterface::CAST_DATETIME:
                return "IF({$value_extractor_expression} IS NULL, $escaped_default_value, CAST({$value_extractor_expression} AS DATETIME))";
            case ValueCasterInterface::CAST_INT:
                return "IF({$value_extractor_expression} IS NULL, $escaped_default_value, CAST({$value_extractor_expression} AS SIGNED INTEGER))";
            case ValueCasterInterface::CAST_FLOAT:
                return "IF({$value_extractor_expression} IS NULL, $escaped_default_value, CAST({$value_extractor_expression} AS DECIMAL(12, 2)))";
            default:
                return "IF({$value_extractor_expression} IS NULL, $escaped_default_value, {$value_extractor_expression})";
        }
    }