diff --git a/tests/CommandPDOTest.php b/tests/CommandPDOTest.php index 40811d067..828c0e582 100644 --- a/tests/CommandPDOTest.php +++ b/tests/CommandPDOTest.php @@ -38,4 +38,25 @@ public function testBindParamsNonWhere(string $sql): void { parent::testBindParamsNonWhere($sql); } + + /** + * {@link https://github.com/yiisoft/db-pgsql/issues/1} + */ + public function testInsertAndReadToArrayColumn(): void + { + $db = $this->getConnection(true); + + $arrValue = [1, 2, 3, 4]; + $insertedData = $db->createCommand()->insertWithReturningPks('{{%table_with_array_col}}', ['array_col' => $arrValue]); + + $this->assertGreaterThan(0, $insertedData['id']); + + $selectData = $db->createCommand('select * from {{%table_with_array_col}} where id=:id', $insertedData)->queryOne(); + + $this->assertEquals('{1,2,3,4}', $selectData['array_col']); + + $columnSchema = $db->getTableSchema('{{%table_with_array_col}}')->getColumn('array_col'); + + $this->assertSame($arrValue, $columnSchema->phpTypecast($selectData['array_col'])); + } } diff --git a/tests/Support/Fixture/pgsql.sql b/tests/Support/Fixture/pgsql.sql index 55c2e7cb5..93a29d00f 100644 --- a/tests/Support/Fixture/pgsql.sql +++ b/tests/Support/Fixture/pgsql.sql @@ -33,6 +33,7 @@ DROP TABLE IF EXISTS "T_constraints_2"; DROP TABLE IF EXISTS "T_constraints_1"; DROP TABLE IF EXISTS "T_upsert"; DROP TABLE IF EXISTS "T_upsert_1"; +DROP TABLE IF EXISTS "table_with_array_col"; DROP SCHEMA IF EXISTS "schema1" CASCADE; DROP SCHEMA IF EXISTS "schema2" CASCADE; @@ -425,3 +426,8 @@ CREATE TABLE "schema2"."custom_type_test_table" ( ); INSERT INTO "schema2"."custom_type_test_table" ("test_type", "test_type2") VALUES (array['VAL1']::"my_type"[], array['VAL2']::"schema2"."my_type2"[]); + +CREATE TABLE "table_with_array_col" ( + "id" SERIAL NOT NULL PRIMARY KEY, + "array_col" integer ARRAY[4] +);