clickhouse 常用函数 算数函数 时间函数 日期函数 字符串函数 比较函数 数据类型函数 逻辑函数 类型转换函数 替换函数 数组函数 随机函数 编码函数 UUID URL IP 函数
算数函数 时间函数 日期函数 字符串函数 比较函数
SELECT toTypeName(0);
SELECT toTypeName(-0);
SELECT toTypeName(-343);
SELECT toTypeName(12.43);
SELECT toTypeName(12.34343);
SELECT toTypeName(toDateTime(1502396027));
SELECT plus(12, 21), plus(10, -10), plus(-10, -10), 1+1;
SELECT minus(10, 5), minus(10, -10),minus(-10, -10);
SELECT multiply(12, 2), multiply(12, -2), multiply(-12, -2);
SELECT divide(12, 4), divide(10, 3), divide(2, 4), divide(-4, -2), divide(-4, 2), divide(-4.5, 3);
SELECT intDiv(10, 3);
SELECT divide(10, 0), divide(-10, 0);
SELECT divide(0, 0);
SELECT intDivOrZero(10, 0);
SELECT modulo(10, 3);
SELECT modulo(10.5, 3);
SELECT negate(10), negate(-10);
SELECT abs(-10), abs(10);
SELECT gcd(12, 24), gcd(-12, -24), gcd(-12, 24);
SELECT lcm(12, 24), lcm(-12, -24), lcm(-3, 4);
SELECT 12 == 12, 12 != 10, 12 == 132, 12 != 12, 12 <> 12;
SELECT equals(12, 12), notEquals(12, 10), equals(12, 10), notEquals(12,123);
SELECT greater(12, 10), greater(10, 12), greater(12, 12);
SELECT greaterOrEquals(12,10), greaterOrEquals(12,12);
SELECT less(12, 21), less(12, 10), less(120, 120);
SELECT lessOrEquals(12, 120), lessOrEquals(12, 12);
SELECT 1 or 12!=10;
SELECT 1 and 12!=10;
SELECT not 1, not 0;
SELECT or(equals(12, 12), notEquals(12, 10));
SELECT and(equals(12, 12), notEquals(12, 10));
SELECT not(1), not(0);
SELECT toInt8(12.3334343), toFloat32(10.002), toFloat64(10.002);
SELECT toString(now());
SELECT now() AS now_local, toString(now(), 'Asia/Yekaterinburg') AS now_yekat;
SELECT now() AS now_local, toDate(now()), toDateTime(now()), toUnixTimestamp(now());
SELECT
'2016-06-15 23:00:00' AS timestamp,
CAST(timestamp AS DateTime) AS datetime,
CAST(timestamp AS Date) AS date,
CAST(timestamp, 'String') AS string,
CAST(timestamp, 'FixedString(22)') AS fixed_string;
WITH
toDate('2022-01-01') AS date,
INTERVAL 1 WEEK AS interval_week,
toIntervalWeek(1) AS interval_to_week,
toIntervalMonth(1) AS interval_to_month
SELECT
date + interval_week,
date + interval_to_week,
date + interval_to_month;
WITH
toDateTime('2022-01-01 12:10:10') as datetime,
INTERVAL 1 HOUR AS interval_hour,
toIntervalHour(1) as invterval_to_hour
SELECT
plus(datetime, interval_hour),
plus(datetime, invterval_to_hour);
SELECT
toDateTime('2022-07-30 10:10:10') AS time,
toUnixTimestamp(time) as unixTimestamp,
toDate(time) as date_local,
toTime(time) as date_time,
toYear(time) as get_year,
toMonth(time) as get_month,
toQuarter(time) as get_quarter,
toHour(time) as get_hour,
toMinute(time) as get_minute,
toSecond(time) as get_second,
toDayOfYear(time) as "当前年份中的第几天",
toDayOfMonth(time) as "当前月份的第几天",
toDayOfWeek(time) as "星期",
toDate(time, 'Asia/Shanghai') AS date_shanghai,
toDateTime(time, 'Asia/Shanghai') AS time_shanghai,
toStartOfYear(time),
toStartOfMonth(time),
toStartOfQuarter(time),
toStartOfDay(time) AS cur_start_daytime,
toStartOfHour(time) as cur_start_hour,
toStartOfMinute(time) AS cur_start_minute,
toRelativeYearNum(time),
toRelativeQuarterNum(time);
SELECT
toDateTime('2022-07-30 14:27:30') as time,
toISOYear(time) AS iso_year,
toISOWeek(time) AS iso_week,
now() AS cur_dateTime1,
today() AS cur_dateTime2,
yesterday() AS yesterday,
toDate(time) as getY_M_d;
SELECT
now() as nowTime,
toYYYYMMDDhhmmss(nowTime),
toYYYYMMDD(nowTime),
toYYYYMM(nowTime);
SELECT
now() as now_time,
toDateTime('2022-07-31 18:20:30') AS def_datetime,
formatDateTime(now_time, '%D') AS now_time_day_month_year,
formatDateTime(def_datetime, '%Y') AS def_datetime_year,
formatDateTime(def_datetime, '%y') AS def_datetime_year_litter,
formatDateTime(def_datetime, '%H') AS hour24,
formatDateTime(def_datetime, '%I') AS hour12,
formatDateTime(def_datetime, '%p') AS PMorAM,
formatDateTime(def_datetime, '%w') AS def_datetime_get_curWeek,
formatDateTime(def_datetime, '%F') AS def_datetime_get_date,
formatDateTime(def_datetime, '%T') AS def_datetime_get_time,
formatDateTime(def_datetime, '%M') AS def_datetime_get_minute,
formatDateTime(def_datetime, '%S') AS def_datetime_get_second;
WITH
toDate('2022-09-09') AS date,
toDateTime('2022-09-09 00:00:00') AS date_time
SELECT
addYears(date, 1) AS add_years_with_date,
addYears(date_time, 0) AS add_years_with_date_time;
WITH
toDate(now()) as date,
toDateTime(now()) as date_time
SELECT
now() as now_time,
addYears(date, 1) AS add_years_with_date,
addYears(date_time, 1) AS add_years_with_date_time,
addMonths(date, 1) AS add_months_with_date,
addMonths(date_time, 1) AS add_months_with_date_time,
addWeeks(date, 1) AS add_weeks_with_date,
addWeeks(date_time, 1) AS add_weeks_with_date_time,
addDays(date, 1) AS add_days_with_date,
addDays(date_time, 1) AS add_days_with_date_time,
addHours(date_time, 1) AS add_hours_with_date_time,
addMinutes(date_time, 1) AS add_minutes_with_date_time,
addSeconds(date_time, 10) AS add_seconds_with_date_time,
addQuarters(date, 1) AS add_quarters_with_date,
addQuarters(date_time, 1) AS add_quarters_with_date_time;
WITH
toDate(now()) as date,
toDateTime(now()) as date_time
SELECT
subtractYears(date, 1) AS subtract_years_with_date,
subtractYears(date_time, 1) AS subtract_years_with_date_time,
subtractQuarters(date, 1) AS subtract_Quarters_with_date,
subtractQuarters(date_time, 1) AS subtract_Quarters_with_date_time,
subtractMonths(date, 1) AS subtract_Months_with_date,
subtractMonths(date_time, 1) AS subtract_Months_with_date_time,
subtractWeeks(date, 1) AS subtract_Weeks_with_date,
subtractWeeks(date_time, 1) AS subtract_Weeks_with_date_time,
subtractDays(date, 1) AS subtract_Days_with_date,
subtractDays(date_time, 1) AS subtract_Days_with_date_time,
subtractHours(date_time, 1) AS subtract_Hours_with_date_time,
subtractMinutes(date_time, 1) AS subtract_Minutes_with_date_time,
subtractSeconds(date_time, 1) AS subtract_Seconds_with_date_time;
SELECT toDate('2022-07-31', 'Asia/GuangZhou') as date_guangzhou;
SELECT toDate('2022-07-31'), toDate('2022-07-31', 'Asia/Beijing') as date_beijing;
SELECT toDateTime('2022-07-31 10:10:10', 'Asia/Shanghai') as date_shanghai;
WITH
toDateTime('2022-07-30 10:10:10', 'Asia/Shanghai') as date_shanghai_one,
toDateTime('2020-10-31 11:20:30', 'Asia/Shanghai') as date_shanghai_two
SELECT
dateDiff('year', date_shanghai_one, date_shanghai_two) as diff_years,
dateDiff('month', date_shanghai_one, date_shanghai_two) as diff_months,
dateDiff('week', date_shanghai_one, date_shanghai_two) as diff_week,
dateDiff('day', date_shanghai_one, date_shanghai_two) as diff_days,
dateDiff('hour', date_shanghai_one, date_shanghai_two) as diff_hours,
dateDiff('minute', date_shanghai_one, date_shanghai_two) as diff_minutes,
dateDiff('second', date_shanghai_one, date_shanghai_two) as diff_seconds;
WITH
now() as date_time
SELECT
dateDiff('year', date_time, addYears(date_time, 1)) as diff_years,
dateDiff('month', date_time, addMonths(date_time, 2)) as diff_months,
dateDiff('week', date_time, addWeeks(date_time, 3)) as diff_week,
dateDiff('day', date_time, addDays(date_time, 3)) as diff_days,
dateDiff('hour', date_time, addHours(date_time, 3)) as diff_hours,
dateDiff('minute', date_time, addMinutes(date_time, 30)) as diff_minutes,
dateDiff('second', date_time, addSeconds(date_time, 35)) as diff_seconds;
SELECT
timeSlots(toDateTime('2012-01-01 12:20:00'), toUInt32(600)) as dateTimeArray,
dateTimeArray[0] as arr_index_0,
dateTimeArray[1] as arr_index_1,
dateTimeArray[2] as arr_index_2,
dateTimeArray[3] as arr_index_3,
dateTimeArray[4] as arr_index_4;
SELECT
timeSlots(now(), toUInt32(600), 20) as dateTimeArray,
dateTimeArray[0] as arr_index_0,
dateTimeArray[1] as arr_index_1,
dateTimeArray[2] as arr_index_2,
dateTimeArray[3] as arr_index_3,
dateTimeArray[4] as arr_index_4,
dateTimeArray[5] as arr_index_5;
SELECT
timeSlots(toDateTime('2012-01-01 12:20:00'), toUInt32(600), 20) as cur_dateTimeArray,
cur_dateTimeArray[0] as arr_index_0,
cur_dateTimeArray[1] as arr_index_1,
cur_dateTimeArray[2] as arr_index_2,
cur_dateTimeArray[3] as arr_index_3,
cur_dateTimeArray[4] as arr_index_4,
cur_dateTimeArray[5] as arr_index_5;
SELECT
length('hello world') as str_length,
empty('hello world'),
notEmpty('hello world'),
lengthUTF8('hello world'),
char_length('hello world'),
character_length('hello world'),
lower('abcd123--'),
upper('abcd123--'),
lowerUTF8('abcd123-/*\8asd-\'), -- abcd123-/8asd
upperUTF8('abcd123
isValidUTF8('abcd123--/*');
SELECT notEmpty(''), notEmpty(NULL), notEmpty('he');
SELECT toValidUTF8('\x61\xF0\x80\x80\x80b');
SELECT reverse('abcdefg'), reverseUTF8('abcdefg');
SELECT format('{1} {0} {1}', 'World', 'Hello');
SELECT format('{0} {0} {1} {1}', 'one', 'two');
SELECT format('{} {}', 'Hello', 'World');
SELECT concat('Hello',' ','World', '!');
SELECT concatAssumeInjective('Hello',' ','World', '!');
SELECT
substring('abcdefg', 1, 3),
substring('你好,世界', 1, 3),
substringUTF8('你好,世界', 1, 3);
SELECT
appendTrailingCharIfAbsent('good','c'),
appendTrailingCharIfAbsent('goodccc','c');
SELECT
convertCharset('hello', 'UTF8','Unicode'),
convertCharset('hello', 'Unicode', 'UTF8'),
convertCharset('hello', 'Unicode', 'ASCII'),
convertCharset('hello', 'ascii', 'ascii'),
convertCharset('hello', 'UTF8','UTF8');
SELECT
base64Encode('username+password'),
base64Decode('dXNlcm5hbWUrcGFzc3dvcmQ='),
tryBase64Decode('dXNlcm5hbWUrcGFzc3dvcmQ=');
SELECT
endsWith('string','g'),
startsWith('string', 'str');
SELECT
trimLeft(' sdfdgs'),
trimRight('abcd '),
trimBoth(' abcd ');
SELECT
POSITION('2121stritr','str') AS positionSearch,
POSITION('你好,hello,12323-你好,你,好sdfddg', '你,好'),
positionUTF8('n12你好','你好') AS positionUTF8,
positionCaseInsensitive('ABCDCDEFABCD','bc') AS positionCaseInsensitive,
locate('hellohellohellohello','ello');
SELECT
multiSearchAllPositions('goodnamegolohihihi', ['dn', 'good']) as multiSearch,
multiSearchAllPositionsCaseInsensitive('nameSsdDFetgfderef', ['SS','fa']) as multiCaseInsensitive,
multiSearchAllPositionsUTF8('nameSsdfazz轴FDFetgfderef', ['Ss','fa', 'zz轴']) AS multiSearchUTF8,
multiSearchAllPositionsCaseInsensitiveUTF8('nameSsdfazz轴功SDFetgfderef', ['Ss','fa', 'zz轴']) AS multiCaseInsensitiveUTF8;
SELECT
match('1232434sadgaDDFSrefds', '[0-9a-zA-Z]'),
match('1232321', '[a-z]');
SELECT
multiMatchAny('abcABC',['[0-9]','[a-zA-Z]']) AS multiMatchAnyOne,
multiMatchAny('123abcABC',['[0-9]','[a-zA-Z]']) AS multiMatchAnyTwo,
multiMatchAnyIndex('123abcABC', ['[0-9]','[a-zA-Z]']) as multiMatchAnyIndex;
SELECT
'hello' LIKE '%h%' as LIKE_UP,
'hello' like 'he' AS like_low,
'hello' not like 'he' AS not_like,
'hello' like '%he%' AS like_litter,
like('adgadgadfa1232', '12') AS like_func,
like('sdfasdfasd', '[a-z]') AS like_func2,
notLike('1232423', '[a-zA-Z]') AS not_like_func;
SELECT
extractAll('hellogoodaimantIdeaIDEAfasd123232', '[0-9]'),
extractAll('12323dSDFRE', '[A-Z]'),
extract('helloclickhouse', '[a-z]');
SELECT
ngramDistance('hello123456789','123') AS ngramDistance,
ngramDistanceCaseInsensitive('hello123456789','123') AS ngramDistanceCaseInsensitive,
ngramDistanceUTF8('hello123456789','123') AS ngramDistanceUTF8,
ngramDistanceCaseInsensitiveUTF8('hello123456789','123') AS ngramDistanceCaseInsensitiveUTF8;
SELECT
replaceOne('hed1234544', '4', '') AS replaceOne,
replaceRegexpOne('hed1234544', '4', '') AS replaceRegexpOne,
replace('hed1234544', '4', '') AS replace,
replaceAll('hed1234544', '4', '') AS replaceAll;
SELECT
toDate(now()) AS now_date,
replaceRegexpOne(toString(now_date), '(\d{4})-(\d{2})-(\d{2})', '\2/\3/\1') AS format_date;
SELECT replaceRegexpOne('Hello, World!', '.', '\0\0\0\0\0\0\0\0\0\0') AS res;
SELECT replaceRegexpAll('hello,world!', '.', '\0\0') as res;
SELECT replaceRegexpAll('hello o o, world.', ' ', '') as res;
SELECT toString('\\');
SELECT
12 > 10 ? 'desc' : 'asc' AS "三元操作符",
if(12 > 10, 'desc' , 'asc') AS "if()函数",
if(12 > 10, NULL, NULL);
SELECT multiIf(1,'one',2,'two',3,'three','not this index');
SELECT
1 * e() AS E,
1 * pi() AS PI,
sqrt(25) AS sqrt_25,
cbrt(27) AS cbrt_27,
exp(10),
exp10(10),
log(10) AS LOG,
log2(10) AS LOG2,
ln(e()) AS LOG10;
SELECT erf(3 / sqrt(2));
SELECT
sin(90),
cos(90),
tan(90),
acos(0),
asin(1),
atan(45);
SELECT
pow(2, 3),
pow(3, 2);
SELECT
intExp2(4),
intExp10(2);
SELECT
floor(toFloat32(12.08098), 2),
floor(toFloat32(12.2323), 2),
floor(toFloat32(12.89788), -1),
floor(toFloat32(12.09590), 3),
floor(toFloat32(12.0987), 3),
floor(10, 2);
SELECT
round(toFloat32(12.1234), 3),
round(toFloat32(12.0025), 3),
round(toFloat32(12.0025), 4),
round(toFloat32(12.0025002323), 100);
SELECT
round(toFloat32(10 / 3)),
round(toFloat32(10 / 3), 2),
round(toFloat32(10.000/3), 3),
round(toFloat32(10.000/3), 6);
SELECT
roundToExp2(12.0129),
roundToExp2(toFloat32(0.01));
SELECT
ceil(12.34343, 3),
ceil(toFloat64(12.34343), 3),
ceil(toFloat32(12.34343), 3),
ceil(12.0011, 3);
SELECT empty([]), empty([1,2,3]), notEmpty([1,2,3]), notEmpty([]);
SELECT
length([]),
length(['a','b','c']),
length([1,2,3]);
SELECT
emptyArrayUInt8(),
emptyArrayUInt16(),
emptyArrayUInt32(),
emptyArrayUInt64(),
emptyArrayDate(),
emptyArrayDateTime(),
emptyArrayInt8(),
emptyArrayInt16(),
emptyArrayInt32(),
emptyArrayInt64();
SELECT
emptyArrayToSingle(emptyArrayInt32()),
emptyArrayToSingle(emptyArrayUInt32()),
emptyArrayToSingle(emptyArrayDate()),
emptyArrayToSingle(emptyArrayDateTime());
SELECT
range(10),
range(2),
range(1);
SELECT
array(1,2,2,3,4) AS "array()函数",
[1,2,3,4] AS "[ ]";
SELECT
arrayConcat(array(1,2),array(2,3),array(4,5)),
arrayConcat(array(1,1),array(2,2),array(3,3)),
arrayConcat(array(1,1),[2,3],array(4,5));
SELECT
arrayElement(array(10,20,3), 1),
arrayElement(array(1,20,3), 2),
arrayElement(array(1,2,30), 3),
arrayElement(array(10,20,3), 0),
arrayElement(array(10,20,3), -3),
arrayElement(array(10,20,3), -2),
arrayElement(array(10,20,3), -1);
SELECT
has([1,2,3], 2),
has(array(1,2,3),2),
has([1,2,NULL], NULL),
has([1,2], 3);
SELECT
hasAll([], []),
hasAll([1,NULL,NULL], [NULL]),
hasAll([1,2,3], [1,2]),
hasAll([1,2,2,3], [2]),
hasAll(array(1,2,2,3), [2]),
hasAll([1,2,3], [4,5]);
SELECT hasAll([[1, 2], [3, 4]], [[1, 2], [3, 5]]);
SELECT
hasAny(array(1,2,3), array(1)),
hasAny(array(1,2,3), array(1,4,56,80)),
hasAny(array(), array()),
hasAny([],[]),
hasAny([1],[]),
hasAny([1,NULL],[]),
hasAny([1,NULL],[NULL,2]);
SELECT indexOf(['one','two','three'], 'one');
SELECT indexOf([1, 2, 4], 4);
SELECT
indexOf(['one','two','three'], 'one'),
indexOf(['one',NULL,NULL], NULL),
indexOf([1, 2, 4], 4);
SELECT length([12,3,4,4,4]);
SELECT array(12,22,31)[1];
WITH
[23,43,565,2,32,34] AS arr
SELECT
arr[1],
arr[length(arr)];
SELECT
countEqual([1, 2, 2, 2, 3, 4], 2),
countEqual([1, 2, NULL, NULL], NULL);
SELECT arrayEnumerate([1,20,20,3]);
SELECT arrayEnumerate(array(11,20,13));
SELECT arrayEnumerate(array(11,20,13,NULL));
SELECT arrayEnumerateUniq([1,1,2,2]);
SELECT arrayPopBack(array(1,2,3,0)) AS res;
SELECT arrayPopFront(array(0,1,2,3)) AS res;
SELECT arrayPushBack([1,2,3], 0) AS res;
SELECT arrayPushFront([1,2,3], 0) AS res;
SELECT arrayResize([1,2,3], 5);
SELECT arrayResize([1,2,3], 2);
SELECT arrayResize([1,2,3], 3);
SELECT arrayResize([array(1,2),array(3,4),array(5,6)], 5);
SELECT arrayResize([1,2,3], 5, 12);
SELECT arrayResize(['one','two','three'], 5);
SELECT arrayResize(['one','two','three'], 5, 'default');
SELECT
arraySlice([1,2,3,4,5,6], 0, 3),
arraySlice([1,2,NULL,5,6], 1, 3),
arraySlice(['one','two',NULL], 1, 3),
arraySlice([1,2,3,4,5,6], 1, 3);
SELECT
arraySort(['a','',NULL,'c','b']) AS hasNullempty1,
arraySort(array('ac','ab','bc','ad',NULL)) AS hasNull,
arraySort(array('ac','','ab',NULL,'bc','ad',NULL)) AS hasNullempty2,
arraySort([5,4,3,2,1]) AS numSorted,
arraySort(['ca','bb','ac']) AS strSorted;
SELECT
arraySort([NULL, 1, 3, NULL, 2]) AS sortedArr,
arrayReverse(sortedArr) AS reverseSortdArr;
SELECT arraySort(x -> -x, [1,2,3]) as res;
SELECT arraySort((x) -> -x, [1,2,3]) as res;
SELECT arraySort(x -> x, [5,4,3,1,2,3]) as res;
SELECT arraySort((x) -> x, [5,4,3,1,2,3]) as res;
SELECT arraySort((x, y) -> y, ['hello', 'world'], [2, 1]) as res;
SELECT arraySort((x, y) -> -y, [0, 1, 2], [1, 2, 3]) as res;
SELECT arraySort([1, nan, 2, NULL, 3, nan, -4, NULL, inf, -inf]);
SELECT
arrayReverse(array('a','b','c',NULL)) AS hasOneNull,
arrayReverse(array('ac','ab','bc','ad',NULL)) AS hasNull,
arrayReverse(array('ac','',NULL,'ab','','bc','ad',NULL)) AS hasNullEmpty,
arrayReverse(array(NULL, 3, NULL, 2, 1)),
arrayReverse([1,2,3,4]);
SELECT arrayReverseSort([1, 3, 3, 0]);
SELECT arrayReverseSort(['hello', 'world', '!']);
SELECT arrayReverseSort([1, nan, 2, NULL, 3, nan, -4, NULL, inf, -inf]) as res;
SELECT arrayReverseSort((x) -> -x, [1, 2, 3]) as res;
SELECT arrayReverseSort((x) -> x, [1, 2, 3]) as res;
SELECT arrayReverseSort((x, y) -> y, ['hello', 'world'], [2, 1]) as res;
SELECT arrayReverseSort((x, y) -> -y, ['hello', 'world'], [2, 1]) as res;
SELECT arrayReverseSort((x, y) -> x, ['hello', 'world'], [2, 1]) as res;
SELECT arrayReverseSort((x, y) -> x, ['hello', 'world'], [1, 2]) as res;
SELECT
arrayUniq([1,2,3]),
arrayUniq([1,2,2,2,3]);
SELECT
arrayUniq([1,2,3],[2,3,4]),
arrayUniq([1,2,2],[1,3,3]);
SELECT arrayJoin([1, 2, 3] AS src) AS dst, 'Hello', src;
SELECT arrayJoin([1,2,3]) * 2;
SELECT arrayJoin([-1,-2,0,1,2]) * 2;
SELECT multiply(arrayJoin([-1,-2,0,1,2]), 2);
SELECT arrayJoin([-4,-2,0,2,4]) / 2;
SELECT divide(arrayJoin([-4,-2,0,2,4]) , 2);
SELECT arrayDifference([1,2,3,4]);
SELECT arrayDifference([1,3,10,50]);
SELECT arrayDistinct(array(1,2,3,4,4,4));
SELECT arrayDistinct([1,2,2,3,4,2,2,5,4,5]);
SELECT arrayDistinct(array(0,1,NULL,3,4,4,4));
SELECT uniq(arrayJoin([1,2,3,6,3]));
SELECT uniqArray([1,2,3,4,1,2,3,4]);
SELECT sumArray([1,2,3,4,5]);
SELECT sum(arraySum([1,2,3,4,5]));
SELECT
arrayEnumerateDense([10,20,20,10,30]) AS numArrEnumDense,
arrayEnumerateDense([10,10,2,12,3,10,12,NULL,NULL]) as arrEnumDenseHasNull,
arrayEnumerateDense([10,20,10,10,20,30]) AS arrEnumDese2;
SELECT
arrayIntersect(['one','two'],['one','two','three']) as uniStrArr1,
arrayIntersect(['aaa','bbb'],['bbb','aaa','three']) as uniStrArr2,
arrayIntersect([1,2],[1,2,3]) as uniArr1,
arrayIntersect([1,2],[1,2,3],[2,3,4],[2,3,4]) as uniArr2;
SELECT
arrayIntersect([1,2], [3,4]),
arrayIntersect([1,2]);
SELECT
arrayReduce('max', [1,2,3]) AS minNum,
arrayReduce('min', [1,2,3]) AS maxNum,
arrayReduce('sum', [1,2,3]) AS sumNum;
SELECT splitByChar(',', 'hello,world!');
SELECT splitByString('or','goodorniceorgreat');
SELECT alphaTokens('abca1abc');
SELECT alphaTokens('abc1232abc2wer3rtty');
SELECT arrayStringConcat([1,2,3], '-');
SELECT arrayStringConcat(['one','two','three']);
SELECT arrayStringConcat(['one','two','three'], '-');
SELECT arrayStringConcat(['one','two','three',''], '-');
SELECT
bitAnd(1,0),
bitAnd(1,1),
bitAnd(1,2),
bitAnd(-1,0),
bitAnd(-1,-2),
bitAnd(-10,-1),
bitOr(1,2),
bitOr(1,0),
bitOr(2,0),
bitOr(0,2);
SELECT bitXor(1, 2), bitXor(20, 15), bitNot(2);
SELECT
halfMD5('HELLO WORLD!'),
halfMD5(12);
SELECT
MD5('drew-zero,78967');
SELECT
intHash32(1221232132132) AS intHash32,
intHash64(1221232132132) AS intHash64,
cityHash64('username') AS cityHash64,
SHA1('1232131') AS sha1,
SHA224('1232131') AS sha224,
SHA256('DREW-ZERO') AS sha256;
SELECT
URLHash('www.baidu.com'),
URLHash('www.baidu.com', 0),
URLHash('www.baidu.com', 1);
SELECT farmHash64('www.runoob.com');
SELECT javaHash('www.baidu.com');
SELECT hiveHash('www.baidu.com');
SELECT
rand(),
rand(10),
rand64(),
rand64(10),
randConstant(),
randConstant();
SELECT
hex('hello world!,hello clickhouse') AS hexStr,
hex(now()) AS hexDatetime,
hex(toDate(now())) AS hexDate;
SELECT UUIDStringToNum('123e4567-e89b-12d3-a456-426655440000');
SELECT bitmaskToArray(10);
SELECT bitmaskToArray(100);
SELECT bitmaskToList(10);
SELECT bitmaskToList(100);
SELECT bitmaskToList(0);
SELECT generateUUIDv4() as randomUUID;
SELECT replaceAll(toString(generateUUIDv4()), '-', '') AS replaceUUID;
SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0') AS uuid;
SELECT
'612f3c40-5d3b-217e-707b-6a546a3d7b29' AS uuid,
UUIDStringToNum(uuid) AS bytes;
SELECT 'a/<@];!~p{jTj={)' AS bytes,
UUIDNumToString(toFixedString(bytes, 16)) AS uuid;
SELECT protocol('http://www.baidu.com');
SELECT protocol('https://www.baidu.com');
SELECT protocol('www.baidu.com');
SELECT domain('http://www.baidu.com');
SELECT domain('https://www.google.com.cn');
SELECT domainWithoutWWW('http://www.baidu.com');
SELECT domainWithoutWWW('www.baidu.com');
SELECT topLevelDomain('http://www.runoob.com.cn');
SELECT topLevelDomain('https://www.huse.edn');
SELECT firstSignificantSubdomain('https://news.yandex.com.tr/');
SELECT cutToFirstSignificantSubdomain('https://news.yandex.com.tr/');
SELECT path('https://blog.csdn.net/u012111465/article/details/85250030');
SELECT pathFull('https://clickhouse.yandex/#quick-start');
SELECT queryString('http://www.baidu.com/?page=1&lr=234');
SELECT queryString('http://www.baidu.com/page=1&lr=234');
SELECT fragment('https://clickhouse.yandex/#quick-start');
SELECT queryStringAndFragment('https://www.baidu.com/s?ie=utf-8&rsv_sug7=100#ei-ai');
SELECT cutWWW('www.baidu.com');
SELECT cutWWW('https://www.baidu.com');
SELECT cutWWW('https://www.baidu.com');
SELECT cutQueryString('http://www.baidu.com/1?page=1');
SELECT cutFragment('http://www.baidu.com/#quick-demo');
SELECT cutQueryStringAndFragment('http://www.baidu.com/1?page=23#we');
SELECT cutURLParameter('http://www.baidu.com/1?page=1#erre&resv=23&name=user','resv');
接受一个UInt32(大端)表示的IPv4的地址,返回相应IPv4的字符串表现形式,格式为A.B.C.D(以点分割的十进制数字)。
与IPv4NumToString函数相反。如果IPv4地址格式无效,则返回0。
与IPv4NumToString类似,但使用xxx替换最后一个字节。
接受FixedString(16)类型的二进制格式的IPv6地址。以文本格式返回此地址的字符串。
与IPv6NumToString的相反。如果IPv6地址格式无效,则返回空字节字符串。
十六进制可以是大写的或小写的。
接受一个UInt32类型的IPv4地址,返回FixedString(16)类型的IPv6地址。
接受一个FixedString(16)类型的IPv6地址,返回一个String,这个String中包含了删除指定位之后的地址的文本格式。
IPv4StringToNum()的别名,它采用字符串形式的IPv4地址并返回IPv4类型的值,该二进制值等于IPv4StringToNum()返回的值。
IPv6StringToNum()的别名,它采用字符串形式的IPv6地址并返回IPv6类型的值,该二进制值等于IPv6StringToNum()返回的值。
接受一个IPv4地址以及一个UInt8类型的CIDR。返回包含子网最低范围以及最高范围的元组。
接受一个IPv6地址以及一个UInt8类型的CIDR。返回包含子网最低范围以及最高范围的元组。
SELECT IF(12 > 10 , 12, 20);
SELECT 12 > 10 ? 12 : 10;
SELECT if(greater(12, 10), 12, 10);
SELECT
equals('hello','hello'),
equals('ab','ba');
SELECT
notEquals('a','b'),
notEquals('a','a'),
notEquals(12, 12),
notEquals(12, 1010);
SELECT
greater(12, 10),
greater(10, 12),
greater(12, 12),
greater('b','a'),
greater('a','b');
SELECT greatest(12,11);
SELECT less(12,23);
SELECT less(120,23);
SELECT greaterOrEquals(12,12);
SELECT greaterOrEquals(120,12);
SELECT lessOrEquals(12,12);
SELECT lessOrEquals(12,129);
SELECT like('a', 'abcd');
SELECT like('a', 'a');