Skip to content

Incorrect parsing PostgreSQL response for "ARRAY" columns #20250

Open
@abolotin

Description

@abolotin

What steps will reproduce the problem?

Creating table:
CREATE TABLE test (data VARCHAR(255)[]);

Filling up:
INSERT INTO test (data) VALUES (ARRAY['qwe', 'asd']);

Creating simple model fro this table, named "Test":

namespace common\models;
class Test extends \yii\db\ActiveRecord {
    public static function tableName() {
        return 'test';
    }
}

Selecting one item of array:

$model=Test::find()->select([new \yii\db\Expression('data[1]')])->one();
print_r($row->toArray());

What is the expected result?

Array
(
    [data] => Array
        (
            [0] => qwe
        )
)

What do you get instead?

Array
(
    [data] => Array
        (
            [0] => we
        )
)

First symbol lost.

Additional info

Q A
Yii version 2.0.49.3
PHP version 8.2.20
Operating system Debian

Problen in yii\db\pgsql\ArrayParser, method parseArray() (line 51) always skips first symbol, because expecting it to be equal to "{". But for "data[1]" query result contains only item value "qwe", not "{qwe}".

Possible solution:
replace for (++$i; $i < $len; ++$i) with for ($i; $i < $len; ++$i) (line 55)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions