Add case insensitive coalesce ifnull, nullif.

This commit is contained in:
ap11 2018-07-30 12:36:27 +03:00 committed by alexey-milovidov
parent 93f1ec2f02
commit 45ce69e73d
5 changed files with 13 additions and 3 deletions

View File

@ -19,9 +19,9 @@ void registerFunctionsNull(FunctionFactory & factory)
{ {
factory.registerFunction<FunctionIsNull>(); factory.registerFunction<FunctionIsNull>();
factory.registerFunction<FunctionIsNotNull>(); factory.registerFunction<FunctionIsNotNull>();
factory.registerFunction<FunctionCoalesce>(); factory.registerFunction<FunctionCoalesce>(FunctionFactory::CaseInsensitive);
factory.registerFunction<FunctionIfNull>(); factory.registerFunction<FunctionIfNull>(FunctionFactory::CaseInsensitive);
factory.registerFunction<FunctionNullIf>(); factory.registerFunction<FunctionNullIf>(FunctionFactory::CaseInsensitive);
factory.registerFunction<FunctionAssumeNotNull>(); factory.registerFunction<FunctionAssumeNotNull>();
factory.registerFunction<FunctionToNullable>(); factory.registerFunction<FunctionToNullable>();
} }

View File

@ -28,3 +28,8 @@ x Nullable(String)
1 UInt8 1 UInt8
1 UInt8 1 UInt8
\N Nullable(Nothing) \N Nullable(Nothing)
0 Nullable(String)
-1 Nullable(String)
2 Nullable(String)
3 Nullable(String)
4 Nullable(String)

View File

@ -17,3 +17,5 @@ SELECT ifNull(nullIf(toString(number), '1'), nullIf(toString(-number), '-3')) AS
SELECT ifNull(NULL, 1) AS res, toTypeName(res); SELECT ifNull(NULL, 1) AS res, toTypeName(res);
SELECT ifNull(1, NULL) AS res, toTypeName(res); SELECT ifNull(1, NULL) AS res, toTypeName(res);
SELECT ifNull(NULL, NULL) AS res, toTypeName(res); SELECT ifNull(NULL, NULL) AS res, toTypeName(res);
SELECT IFNULL(NULLIF(toString(number), '1'), NULLIF(toString(-number), '-3')) AS res, toTypeName(res) FROM system.numbers LIMIT 5;

View File

@ -1,4 +1,5 @@
\N \N \N 1 1 1 1 \N \N \N 1 1 1 1
\N \N 1
0 Nullable(UInt64) 0 Nullable(UInt64)
\N Nullable(UInt64) \N Nullable(UInt64)
2 Nullable(UInt64) 2 Nullable(UInt64)

View File

@ -1,6 +1,8 @@
SELECT coalesce(), coalesce(NULL), coalesce(NULL, NULL), SELECT coalesce(), coalesce(NULL), coalesce(NULL, NULL),
coalesce(1), coalesce(1, NULL), coalesce(NULL, 1), coalesce(NULL, 1, NULL); coalesce(1), coalesce(1, NULL), coalesce(NULL, 1), coalesce(NULL, 1, NULL);
SELECT COALESCE(), COALESCE(NULL), COALESCE(1, NULL);
SELECT coalesce(number % 2 = 0 ? number : NULL, number % 3 = 0 ? number : NULL, number % 5 = 0 ? number : NULL) AS res, toTypeName(res) FROM system.numbers LIMIT 15; SELECT coalesce(number % 2 = 0 ? number : NULL, number % 3 = 0 ? number : NULL, number % 5 = 0 ? number : NULL) AS res, toTypeName(res) FROM system.numbers LIMIT 15;
SELECT coalesce(number % 2 = 0 ? number : NULL, number % 3 = 0 ? number : NULL, number) AS res, toTypeName(res) FROM system.numbers LIMIT 15; SELECT coalesce(number % 2 = 0 ? number : NULL, number % 3 = 0 ? number : NULL, number) AS res, toTypeName(res) FROM system.numbers LIMIT 15;
SELECT coalesce(number % 2 = 0 ? number : NULL, number % 3 = 0 ? number : NULL, 100) AS res, toTypeName(res) FROM system.numbers LIMIT 15; SELECT coalesce(number % 2 = 0 ? number : NULL, number % 3 = 0 ? number : NULL, 100) AS res, toTypeName(res) FROM system.numbers LIMIT 15;