Zum Inhalt

Polyfills on ClickHouse

A polyfill is how Provisa gives a PostgreSQL client PostgreSQL's behaviour on ClickHouse (dialects: clickhouse). Each feature has a read polyfill, how its values and operations are computed on the engine, and a write polyfill, how its values reach the engine; each states its limitations.

This page lists every feature that has a polyfill or a limitation on ClickHouse. A feature ClickHouse does natively with no difference from PostgreSQL is left out: 1 of the grid's 12 features are left out as native. The conformance runs check the omission: a feature left out that answers otherwise than PostgreSQL fails the run.

Rules on this page: 12, of which 0 are only the name of a rewrite function. A rule is printed as the translator runs it: the PostgreSQL pattern, its holes written $name (typed with ::type), then the engine's replacement.

FeatureRead polyfillRead limitationsWrite polyfillWrite limitations
array_ndims
The number of an array's dimensions.
array_ndims($a::anyarray)
=>
CAST(CASE WHEN length($a) > 0 THEN countSubstrings(toTypeName($a), 'Array(') END AS Nullable(Int32))
array_dims
The text of an array's dimensions, such as [1:2][1:3].
array_dims($a::anyarray)
=>
CASE WHEN length($a) > 0 THEN arrayStringConcat(arrayMap(d -> concat('[1:', toString(CASE d WHEN 1 THEN JSONLength(toJSONString($a)) WHEN 2 THEN JSONLength(toJSONString($a), 1) WHEN 3 THEN JSONLength(toJSONString($a), 1, 1) WHEN 4 THEN JSONLength(toJSONString($a), 1, 1, 1) WHEN 5 THEN JSONLength(toJSONString($a), 1, 1, 1, 1) WHEN 6 THEN JSONLength(toJSONString($a), 1, 1, 1, 1, 1) END), ']'), range(1, assumeNotNull(CAST(CASE WHEN length($a) > 0 THEN countSubstrings(toTypeName($a), 'Array(') END AS Nullable(Int32))) + 1)), '') END
array_lower
The lower bound of a dimension: 1, as a list's index starts there.
array_lower($a::anyarray, $d::integer)
=>
CAST(CASE WHEN $d BETWEEN 1 AND CAST(CASE WHEN length($a) > 0 THEN countSubstrings(toTypeName($a), 'Array(') END AS Nullable(Int32)) THEN 1 END AS Nullable(Int32))
array_upper
The upper bound of a dimension: its length.
array_upper($a::anyarray, $d::integer)
=>
CAST(CASE WHEN $d BETWEEN 1 AND CAST(CASE WHEN length($a) > 0 THEN countSubstrings(toTypeName($a), 'Array(') END AS Nullable(Int32)) THEN CASE $d WHEN 1 THEN JSONLength(toJSONString($a)) WHEN 2 THEN JSONLength(toJSONString($a), 1) WHEN 3 THEN JSONLength(toJSONString($a), 1, 1) WHEN 4 THEN JSONLength(toJSONString($a), 1, 1, 1) WHEN 5 THEN JSONLength(toJSONString($a), 1, 1, 1, 1) WHEN 6 THEN JSONLength(toJSONString($a), 1, 1, 1, 1, 1) END END AS Nullable(Int32))
array_fill
An array of a value repeated to the dimensions given.
array_fill($v::anyelement, $dims::integer[])
=>
arrayWithConstant(throwIf(length($dims) <> 1, 'postgresql-error 0A000: array_fill does not read this value <end of postgresql-error>') + assumeNotNull($dims[1]), $v)
array_fill($v::anyelement, $dims::integer[], $lower_bounds::integer[])
=>
arrayWithConstant(throwIf(length($dims) <> 1 OR NOT arrayAll(_b -> _b = 1, $lower_bounds), 'postgresql-error 0A000: array_fill does not read this value <end of postgresql-error>') + assumeNotNull($dims[1]), $v)
  • Only one dimension with a lower bound of 1: any other shape is refused. 0A000 array_fill does not read this value
array_positions
The positions of every element equal to a value, a NULL equal to a NULL.
array_positions($a::anycompatiblearray, $v::anycompatible)
=>
arrayMap(_p -> toInt32(_p.2), arrayFilter(_p -> ((_p.1 IS NULL AND $v IS NULL) OR _p.1 = $v), arrayZip($a, arrayEnumerate($a))))
array_replace
Each element equal to a value replaced by another, a NULL equal to a NULL.
array_replace($a::anycompatiblearray, $v::anycompatible, $w::anycompatible)
=>
arrayMap(_x -> CASE WHEN ((_x IS NULL AND $v IS NULL) OR _x = $v) THEN $w ELSE _x END, $a)
array_sample
A number of an array's elements, chosen at random.
array_sample($a::anyarray, $n::integer)
=>
arraySlice(arrayShuffle($a), 1 + throwIf($n IS NULL OR $n < 0 OR $n > length($a), 'postgresql-error 0A000: array_sample does not read this value <end of postgresql-error>'), $n)
  • An out-of-range count is refused with 0A000, not PostgreSQL's 22023 and its message. 0A000 array_sample does not read this value
array_shuffle
An array's elements in a random order.
array_shuffle($a::anyarray)
=>
arrayShuffle($a)
trim_array
An array without its last elements.
trim_array($a::anyarray, $n::integer)
=>
arraySlice($a, 1 + throwIf($n IS NULL OR $n < 0 OR $n > length($a), 'postgresql-error 0A000: trim_array does not read this value <end of postgresql-error>'), length($a) - $n)
  • An out-of-range count is refused with 0A000, not PostgreSQL's 2202E and its message. 0A000 trim_array does not read this value
generate_subscripts
The subscripts of a dimension, as rows, in either order.
generate_subscripts($a::anyarray, $d::integer, $reverse::boolean)
=>
refused (its error is under the limitations)
  • Refused: generate_subscripts($a::anyarray, $d::integer, $reverse::boolean). 0A000 generate_subscripts() has no form on clickhouse