跳转至

Polyfills on DuckDB

A polyfill is how Provisa gives a PostgreSQL client PostgreSQL's behaviour on DuckDB (dialects: duckdb). 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 DuckDB. A feature DuckDB does natively with no difference from PostgreSQL is left out: 0 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: 13, 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 len($a) > 0 THEN length(regexp_extract(typeof($a), '(\[\])+$')) // 2 END AS INTEGER)
array_dims
The text of an array's dimensions, such as [1:2][1:3].
array_dims($a::anyarray)
=>
array_to_string(list_transform(range(CAST(CASE WHEN len($a) > 0 THEN length(regexp_extract(typeof($a), '(\[\])+$')) // 2 END AS INTEGER)), _d -> '[1:' || json_array_length(to_json($a), '$' || repeat('[0]', CAST(_d AS INTEGER))) || ']'), '')
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 len($a) > 0 THEN length(regexp_extract(typeof($a), '(\[\])+$')) // 2 END AS INTEGER) THEN 1 END AS INTEGER)
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 len($a) > 0 THEN length(regexp_extract(typeof($a), '(\[\])+$')) // 2 END AS INTEGER) THEN json_array_length(to_json($a), '$' || repeat('[0]', CAST($d - 1 AS INTEGER))) END AS INTEGER)
array_length
The length of a dimension; NULL for a dimension the array does not have.
array_length($a::anyarray, $d::integer)
=>
CAST(CASE WHEN $d BETWEEN 1 AND CAST(CASE WHEN len($a) > 0 THEN length(regexp_extract(typeof($a), '(\[\])+$')) // 2 END AS INTEGER) THEN json_array_length(to_json($a), '$' || repeat('[0]', CAST($d - 1 AS INTEGER))) END AS INTEGER)
array_fill
An array of a value repeated to the dimensions given.
array_fill($v::anyelement, $dims::integer[])
=>
CASE WHEN $dims IS NULL THEN error('postgresql-error 22004: ' || 'dimension array or low bound array cannot be null') WHEN len($dims) = 1 THEN list_transform(range($dims[1]), _i -> $v) ELSE error('postgresql-error 0A000: ' || 'array_fill does not read this value') END
array_fill($v::anyelement, $dims::integer[], $lower_bounds::integer[])
=>
CASE WHEN $dims IS NULL OR $lower_bounds IS NULL THEN error('postgresql-error 22004: ' || 'dimension array or low bound array cannot be null') WHEN len($dims) = 1 AND list_filter($lower_bounds, _b -> _b <> 1) = [] THEN list_transform(range($dims[1]), _i -> $v) ELSE error('postgresql-error 0A000: ' || 'array_fill does not read this value') END
  • 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)
=>
CAST(list_filter(range(1, len($a) + 1), _i -> $a[_i] IS NOT DISTINCT FROM $v) AS INTEGER[])
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)
=>
list_transform($a, _x -> CASE WHEN _x IS NOT DISTINCT FROM $v THEN $w ELSE _x END)
array_sample
A number of an array's elements, chosen at random.
array_sample($a::anyarray, $n::integer)
=>
CASE WHEN $a IS NULL OR $n IS NULL THEN NULL WHEN $n < 0 OR $n > len($a) THEN error('postgresql-error 22023: ' || 'sample size must be between 0 and ' || len($a)) ELSE list_transform(list_sort(list_transform($a, _x -> {'k': random(), 'v': _x})), _e -> _e.v)[1:$n] END
array_shuffle
An array's elements in a random order.
array_shuffle($a::anyarray)
=>
list_transform(list_sort(list_transform($a, _x -> {'k': random(), 'v': _x})), _e -> _e.v)
trim_array
An array without its last elements.
trim_array($a::anyarray, $n::integer)
=>
CASE WHEN $a IS NULL OR $n IS NULL THEN NULL WHEN $n < 0 OR $n > len($a) THEN error('postgresql-error 2202E: ' || 'number of elements to trim must be between 0 and ' || len($a)) ELSE $a[1:len($a) - $n] END
generate_subscripts
The subscripts of a dimension, as rows, in either order.
generate_subscripts($a::anyarray, $d::integer, $reverse::boolean)
=>
unnest(CASE WHEN $reverse THEN range(CAST(CASE WHEN $d BETWEEN 1 AND CAST(CASE WHEN len($a) > 0 THEN length(regexp_extract(typeof($a), '(\[\])+$')) // 2 END AS INTEGER) THEN json_array_length(to_json($a), '$' || repeat('[0]', CAST($d - 1 AS INTEGER))) END AS INTEGER), 0, -1) ELSE range(1, CAST(CASE WHEN $d BETWEEN 1 AND CAST(CASE WHEN len($a) > 0 THEN length(regexp_extract(typeof($a), '(\[\])+$')) // 2 END AS INTEGER) THEN json_array_length(to_json($a), '$' || repeat('[0]', CAST($d - 1 AS INTEGER))) END AS INTEGER) + 1) END)