ClickHouse/tests/queries/0_stateless/02119_sumcount.sql

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

174 lines
4.8 KiB
MySQL
Raw Normal View History

2021-11-24 10:58:58 +00:00
-- Integer types are added as integers
2022-02-02 19:50:33 +00:00
SELECT toTypeName(sumCount(v)), sumCount(v) FROM
(
SELECT v FROM
(
SELECT '9007199254740992'::UInt64 AS v
UNION ALL
SELECT '1'::UInt64 AS v
UNION ALL SELECT '1'::UInt64 AS v
)
ORDER BY v
);
SELECT toTypeName(sumCount(v)), sumCount(v) FROM
(
SELECT v FROM
(
SELECT '9007199254740992'::Nullable(UInt64) AS v
UNION ALL
SELECT '1'::Nullable(UInt64) AS v
UNION ALL
SELECT '1'::Nullable(UInt64) AS v
)
ORDER BY v
);
2022-12-22 17:40:06 +00:00
SET allow_suspicious_low_cardinality_types=1;
2022-02-02 19:50:33 +00:00
SELECT toTypeName(sumCount(v)), sumCount(v) FROM
(
SELECT v FROM
(
SELECT '9007199254740992'::LowCardinality(UInt64) AS v
UNION ALL
SELECT '1'::LowCardinality(UInt64) AS v
UNION ALL
SELECT '1'::LowCardinality(UInt64) AS v
)
ORDER BY v
);
SELECT toTypeName(sumCount(v)), sumCount(v) FROM
(
SELECT v FROM
(
SELECT '9007199254740992'::LowCardinality(Nullable(UInt64)) AS v
UNION ALL
SELECT '1'::LowCardinality(Nullable(UInt64)) AS v
UNION ALL
SELECT '1'::LowCardinality(Nullable(UInt64)) AS v
)
ORDER BY v
);
2021-11-24 10:58:58 +00:00
2022-02-02 19:50:33 +00:00
-- -- Float64 types are added as Float64
SELECT toTypeName(sumCount(v)), sumCount(v) FROM
(
SELECT v FROM
(
SELECT '9007199254740992'::Float64 AS v
UNION ALL
SELECT '1'::Float64 AS v
UNION ALL SELECT '1'::Float64 AS v
)
ORDER BY v
);
SELECT toTypeName(sumCount(v)), sumCount(v) FROM
(
SELECT v FROM
(
SELECT '9007199254740992'::Nullable(Float64) AS v
UNION ALL
SELECT '1'::Nullable(Float64) AS v
UNION ALL
SELECT '1'::Nullable(Float64) AS v
)
ORDER BY v
);
SELECT toTypeName(sumCount(v)), sumCount(v) FROM
(
SELECT v FROM
(
SELECT '9007199254740992'::LowCardinality(Float64) AS v
UNION ALL
SELECT '1'::LowCardinality(Float64) AS v
UNION ALL
SELECT '1'::LowCardinality(Float64) AS v
)
ORDER BY v
);
SELECT toTypeName(sumCount(v)), sumCount(v) FROM
(
SELECT v FROM
(
SELECT '9007199254740992'::LowCardinality(Nullable(Float64)) AS v
UNION ALL
SELECT '1'::LowCardinality(Nullable(Float64)) AS v
UNION ALL
SELECT '1'::LowCardinality(Nullable(Float64)) AS v
)
ORDER BY v
);
2021-11-24 10:58:58 +00:00
2022-02-02 19:50:33 +00:00
-- -- Float32 are added as Float64
SELECT toTypeName(sumCount(v)), sumCount(v) FROM
(
SELECT v FROM
(
SELECT '16777216'::Float32 AS v
UNION ALL
SELECT '1'::Float32 AS v
UNION ALL
SELECT '1'::Float32 AS v
)
ORDER BY v
);
SELECT toTypeName(sumCount(v)), sumCount(v) FROM
(
SELECT v FROM
(
SELECT '16777216'::Nullable(Float32) AS v
UNION ALL
SELECT '1'::Nullable(Float32) AS v
UNION ALL
SELECT '1'::Nullable(Float32) AS v
)
ORDER BY v
);
SELECT toTypeName(sumCount(v)), sumCount(v) FROM
(
SELECT v FROM
(
SELECT '16777216'::LowCardinality(Float32) AS v
UNION ALL
SELECT '1'::LowCardinality(Float32) AS v
UNION ALL
SELECT '1'::LowCardinality(Float32) AS v
)
ORDER BY v
);
SELECT toTypeName(sumCount(v)), sumCount(v) FROM
(
SELECT v FROM
(
SELECT '16777216'::LowCardinality(Nullable(Float32)) AS v
UNION ALL
SELECT '1'::LowCardinality(Nullable(Float32)) AS v
UNION ALL
SELECT '1'::LowCardinality(Nullable(Float32)) AS v
)
ORDER BY v
);
2021-11-24 10:58:58 +00:00
-- Small integer types use their sign/unsigned 64 byte supertype
SELECT toTypeName(sumCount(number::Int8)), sumCount(number::Int8) FROM numbers(120);
SELECT toTypeName(sumCount(number::UInt8)), sumCount(number::UInt8) FROM numbers(250);
-- Greater integers use their own type
SELECT toTypeName(sumCount(v)), sumCount(v) FROM (SELECT '1'::Int128 AS v FROM numbers(100));
SELECT toTypeName(sumCount(v)), sumCount(v) FROM (SELECT '1'::Int256 AS v FROM numbers(100));
SELECT toTypeName(sumCount(v)), sumCount(v) FROM (SELECT '1'::UInt128 AS v FROM numbers(100));
SELECT toTypeName(sumCount(v)), sumCount(v) FROM (SELECT '1'::UInt256 AS v FROM numbers(100));
-- Decimal types
SELECT toTypeName(sumCount(v)), sumCount(v) FROM (SELECT '1.001'::Decimal(3, 3) AS v FROM numbers(100));
-- Other types
SELECT toTypeName(sumCount(v)), sumCount(v) FROM (SELECT 'a'::String AS v); -- { serverError 43 }
SELECT toTypeName(sumCount(v)), sumCount(v) FROM (SELECT now()::DateTime AS v); -- { serverError 43 }
2021-11-25 12:50:04 +00:00
-- SumCountIf
SELECT sumCountIf(n, n > 10) FROM (SELECT number AS n FROM system.numbers LIMIT 100 );
SELECT sumCountIf(n, n > 10) FROM (SELECT toNullable(number) AS n FROM system.numbers LIMIT 100);
SELECT sumCountIf(n, n > 10) FROM (SELECT If(number % 2 == 0, number, NULL) AS n FROM system.numbers LIMIT 100);