Hologres supports a subset of ClickHouse functions natively and provides equivalent implementations for other commonly used ClickHouse functions. The following sections cover each function category, list the Hologres equivalents, and include runnable examples.
String functions
The syntax of commonly used ClickHouse string functions—including LENGTH, LOWER, UPPER, CONCAT, SUBSTRING, and TRIM—is identical to their Hologres counterparts. For the full list, see String functions.
Mathematical functions
The syntax of commonly used ClickHouse mathematical functions—including CBRT, DEGREES, EXP, IN, LOG, PI, RADIANS, SIGN, and SQRT—is identical to their Hologres counterparts. For the full list, see Mathematical functions.
Type conversion functions
Hologres V1.3.36 and later support the following ClickHouse-style type conversion functions. Constants cannot be used as input parameters. To convert data types not covered by these functions, use the CAST(col AS type) or col::type syntax instead.
Passing a value of an incompatible type returns an error. For example, passing a non-numeric string to toInt64 fails because the source and target types are incompatible.
| ClickHouse function | Hologres equivalent | Return type |
|---|---|---|
toString(anyelement) |
toString(anyelement) |
TEXT |
toInt64(anyelement) |
toInt64(anyelement) |
BIGINT |
toInt32(anyelement) |
toInt32(anyelement) |
INT |
toDate(text) |
toDate(text) |
DATE |
toFloat64(anyelement) |
toFloat64(anyelement) |
DOUBLE PRECISION |
The following examples use the table public.tb1, created with:
CREATE TABLE public.tb1 (
id bigint NOT NULL,
id_text text,
data_date text,
data_float text,
data_text text
);
INSERT INTO public.tb1 VALUES (1234,'123','20190102','1.23','hologres');
toString(anyelement)
Converts a value of any type to TEXT.
SELECT toString(id) FROM public.tb1;1234
toInt64(anyelement)
Converts a numeric value (other than BIGINT) to BIGINT.
SELECT toInt64(id_text) FROM public.tb1;1234
toInt32(anyelement)
Converts a numeric value (other than INT) to INT.
SELECT toInt32(id_text) FROM public.tb1;123
toDate(text)
Converts a TEXT value to DATE. The input must be in a valid date format; otherwise, an error is returned.
Successful conversion:
SELECT toDate(data_date) FROM public.tb1;2019-01-02
Failed conversion (incompatible format):
SELECT toDate(data_text) FROM public.tb1;ERROR: *** invalid input syntax for type date ***
toFloat64(anyelement)
Converts a numeric value (other than DOUBLE PRECISION) to DOUBLE PRECISION.
SELECT toFloat64(data_float) FROM public.tb1;1.23
Datetime functions
For the full list of datetime functions supported by Hologres, see Datetime conversion functions.
| ClickHouse function | Hologres equivalent |
|---|---|
toYear, toMonth, toQuarter |
extract(field FROM timestamp) or date_part(text, timestamp) |
addDays, addMonths, addYears |
+ operator with interval |
subtractDays, subtractMonths, subtractYears |
- operator with interval |
toYear, toMonth, and toQuarter
Extracts the year, month, or quarter from a timestamp. Use extract(field FROM timestamp) or date_part(text, timestamp). For details, see Datetime truncation functions.
Extract the month:
SELECT extract(month FROM timestamp '2001-02-16 20:38:40');2
Extract the quarter:
SELECT extract(quarter FROM timestamp '2001-02-16 20:38:40');1
addDays, addMonths, and addYears
Adds a time interval to a date or timestamp using the + operator.
SELECT date '2001-09-28' + interval '1 hour';2001-09-28 01:00:00
subtractDays, subtractMonths, and subtractYears
Subtracts a time interval from a date or timestamp using the - operator.
SELECT date '2001-09-28' - interval '1 day';2001-09-27 00:00:00
Aggregate functions
For the full list of aggregate functions supported by Hologres, see General-purpose aggregate functions. For specialized functions, see APPROX_COUNT_DISTINCT, UNIQ, and MAX_BY and MIN_BY.
| ClickHouse function | Hologres equivalent | Available since |
|---|---|---|
argMin(x, y) |
min_by(x, y) |
V1.3.36 |
argMax(x, y) |
max_by(x, y) |
V1.3.36 |
groupArray(anyelement) |
array_agg(anyelement) |
— |
argMin(x, y)
Returns the value of x that corresponds to the minimum value of y. If the minimum y maps to multiple x values, the minimum of those x values is returned.
Requires Hologres V1.3.36 or later. For the sample table definition, see Sample data.
SELECT min_by(name, cost) FROM test; min_by
--------
cc
(1 row)
argMax(x, y)
Returns the value of x that corresponds to the maximum value of y. If the maximum y maps to multiple x values, the maximum of those x values is returned.
Requires Hologres V1.3.36 or later. For the sample table definition, see Sample data.
SELECT id, max_by(name, cost) FROM test GROUP BY id; id | max_by
----+--------
2 | bb
1 | aaa
3 | c
(3 rows)
groupArray(anyelement)
Concatenates all values of an expression into an array. Use array_agg(anyelement).
CREATE TABLE test_array_agg_int (c1 int);
INSERT INTO test_array_agg_int VALUES (1), (2);
SELECT array_agg(c1) FROM test_array_agg_int; array_agg
-----------
{1,2}
(1 row)
Array functions
For the full list of array functions supported by Hologres, see Array functions.
| ClickHouse function | Hologres equivalent | Available since |
|---|---|---|
arrayJoin(anyarray) |
unnest(anyarray) |
— |
arrayConcat(anyarray, anyarray...) |
array_cat(anyarray, anyarray) |
— |
arrayDistinct(anyarray) |
array_distinct(anyarray) |
V1.3.19 |
arrayMin(anyarray) |
array_min(anyarray) |
1.3.19 |
arrayMax(anyarray) |
array_max(anyarray) |
1.3.19 |
arraySum(anyarray) |
unnest + sum |
— |
arrayJoin(anyarray)
Expands each array element into a separate row. Use unnest(anyarray).
SELECT unnest(ARRAY[1,2]);1
2
arrayConcat(anyarray, anyarray...)
Concatenates arrays. Use array_cat(anyarray, anyarray). Because array_cat accepts two arrays at a time, chain multiple calls to concatenate more than two arrays.
SELECT array_cat(array_cat(ARRAY[1,2], ARRAY[3,4]), ARRAY[5,6]);{1,2,3,4,5,6}
arrayDistinct(anyarray)
Returns a new array with duplicate elements removed. Use array_distinct(anyarray).
Requires Hologres V1.3.19 or later. Constants cannot be used as input parameters.
CREATE TABLE test_array_distinct_text (c1 text[]);
INSERT INTO test_array_distinct_text
VALUES (ARRAY['holo', 'hello', 'holo', 'SQL', 'SQL']), (ARRAY[]::text[]);
SELECT c1, array_distinct(c1) FROM test_array_distinct_text; c1 | array_distinct
---------------------------+------------------
{holo,hello,holo,SQL,SQL} | {SQL,hello,holo}
{} | {NULL}
(2 rows)
arrayMin(anyarray)
Returns the minimum value in an array. Use array_min(anyarray).
Requires Hologres 1.3.19 or later. Constants cannot be used as input parameters.
CREATE TABLE test_array_min_text (c1 text[]);
INSERT INTO test_array_min_text
VALUES (NULL), (ARRAY['hello', 'holo', 'blackhole', 'array']);
SELECT c1, array_min(c1) FROM test_array_min_text; c1 | array_min
------------------------------+-----------
|
{hello,holo,blackhole,array} | array
(2 rows)
arrayMax(anyarray)
Returns the maximum value in an array. Use array_max(anyarray).
Requires Hologres 1.3.19 or later. Constants cannot be used as input parameters.
CREATE TABLE test_array_max_int (c1 int[]);
INSERT INTO test_array_max_int VALUES (NULL), (ARRAY[-2, NULL, -3, -12, -7]);
SELECT c1, array_max(c1) FROM test_array_max_int; c1 | array_max
------------------+-----------
|
{-2,0,-3,-12,-7} | 0
(2 rows)
arraySum(anyarray)
Returns the sum of all elements in an array. Use unnest to expand the array into rows, then apply sum.
SELECT sum(ele) FROM (SELECT unnest(ARRAY[1,2,4]) AS ele) a;7
Bitmap functions
For the full list of Roaring bitmap functions supported by Hologres, see Roaring bitmap functions.
| ClickHouse function | Hologres equivalent |
|---|---|
bitmapToArray(roaringbitmap) |
rb_to_array(roaringbitmap) |
groupBitmapState(integer) |
rb_build_agg(integer) |
groupBitmap(integer) |
rb_cardinality(rb_build_agg(integer)) |
groupBitmapAndState(roaringbitmap) |
rb_and_agg(roaringbitmap) |
groupBitmapOrState(roaringbitmap) |
rb_or_agg(roaringbitmap) |
groupBitmapAnd(roaringbitmap) |
rb_and_cardinality_agg(roaringbitmap) |
groupBitmapOr(roaringbitmap) |
rb_or_cardinality_agg(roaringbitmap) |
bitmapToArray(roaringbitmap)
Converts a Roaring bitmap to an integer array. Use rb_to_array(roaringbitmap).
SELECT rb_to_array(rb_build('{1,2,3}'));{1,2,3}
groupBitmapState(integer)
Builds a Roaring bitmap from a group of integer values. Use rb_build_agg(integer).
SELECT rb_build_agg(1);\x3a3000000100000000000000100000000100
groupBitmap(integer)
Calculates the cardinality of a Roaring bitmap built from a group of integer values. Use rb_cardinality(rb_build_agg(integer))—rb_build_agg first aggregates the values into a Roaring bitmap, then rb_cardinality counts the distinct elements.
SELECT rb_cardinality(rb_build_agg(1));1
groupBitmapAndState(roaringbitmap)
Performs an AND aggregate operation across Roaring bitmaps and returns the resulting bitmap. Use rb_and_agg(roaringbitmap).
SELECT rb_and_agg(rb_build('{1,2,3}'));\x3a300000010000000000020010000000010002000300
groupBitmapOrState(roaringbitmap)
Performs an OR aggregate operation across Roaring bitmaps and returns the resulting bitmap. Use rb_or_agg(roaringbitmap).
SELECT rb_or_agg(rb_build('{1,2,3}'));\x3a300000010000000000020010000000010002000300
groupBitmapAnd(roaringbitmap)
Performs an AND aggregate operation across Roaring bitmaps and returns the cardinality of the resulting bitmap. Use rb_and_cardinality_agg(roaringbitmap).
SELECT rb_and_cardinality_agg(rb_build('{1,2,3}'));3
groupBitmapOr(roaringbitmap)
Performs an OR aggregate operation across Roaring bitmaps and returns the cardinality of the resulting bitmap. Use rb_or_cardinality_agg(roaringbitmap).
SELECT rb_or_cardinality_agg(rb_build('{1,2,3}'));3
Hash functions
sipHash64(text)
Returns a 64-bit SipHash value for a text input. In ClickHouse, the return type is UInt64; in Hologres, it is BIGINT. Use hg_sip_hash_64(text).
Requires Hologres V2.0.1 or later. Constants cannot be used as input parameters.
CREATE TABLE test_hg_sip_hash_64_text (c1 text);
INSERT INTO test_hg_sip_hash_64_text VALUES ('abc');
SELECT hg_sip_hash_64(c1) FROM test_hg_sip_hash_64_text;4596069200710135518
Other functions
Hologres is compatible with most PostgreSQL functions. Beyond the string and mathematical functions described in this topic, many PostgreSQL functions share the same semantics as their ClickHouse counterparts. For details, see PostgreSQL.