PG::TextDecoder::Array decodeы incorrectly arrays with nonstandard lower bound index

Issue #272 resolved
hbda NA
created an issue

By default, in Postgresql the lower bound index value of an array's dimensions is set to one. To represent arrays with other lower bounds, the array subscript ranges can be specified explicitly before writing the array contents. This decoration consists of square brackets ([]) around each array dimension's lower and upper bounds, with a colon (:) delimiter character in between. The array dimension decoration is followed by an equal sign (=). This is described in documentation. For example:


This is one-dimensional array. But if try decode it by PG::TextDecoder::Array "text[]", delimiter: ',').decode("[0:1]={foo,bar}")

it returns two-dimensional array

[["foo", "bar"]]

Decoder parse arrays without bounds description correctly. "text[]", delimiter: ',').decode("{foo,bar}")
=> ["foo", "bar"]

The problem is reproduced in versions 0.18.4 and 1.0.0.

Comments (6)

  1. Lars Kanis

    Thanks for the report!

    I wonder how [-3:-2]={foo,bar} could be mapped to ruby, so that it's useful? I think PG::TextDecoder::Array should just ignore the bounds and return a (possibly multidimensional) Array. We could then introduce something like PG::TextDecoder::ArrayWithBounds which returns an instance of, :dimensions) with the possibly multidimensional Array and its bounds.

  2. hbda NA reporter

    I think PG::TextDecoder::Array should ignore the bounds and return array with correct numbers of dimensions. It is better solution than current behavior.

  3. hbda NA reporter

    I thought a little more. Decoder shouldn't just ignore the bounds. This leads to the loss of some information. For example we use this syntax to compress arrays with leading nils.

    [3:3]={foo} => [nil, nil, "foo"]

    But this is a special case. I think returning an instance of, :dimensions) is a good solution.

  4. Log in to comment