Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/Provider/QueryBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,4 +636,26 @@ public static function multiOperandFunctionBuilder(): array
],
];
}

public static function upsertWithMultiOperandFunctions(): array
{
$data = parent::upsertWithMultiOperandFunctions();

$data[0][3] = 'INSERT INTO "test_upsert_with_functions"'
. ' ("id", "array_col", "greatest_col", "least_col", "longest_col", "shortest_col")'
. ' VALUES (1, ARRAY[3,4,5]::int[], 5, 5, :qp0, :qp1) ON CONFLICT ("id") DO UPDATE SET'
. ' "array_col"=ARRAY(SELECT DISTINCT UNNEST("test_upsert_with_functions"."array_col"::int4[] || EXCLUDED."array_col"::int4[]) ORDER BY 1)::int4[],'
. ' "greatest_col"=GREATEST("test_upsert_with_functions"."greatest_col", EXCLUDED."greatest_col"),'
. ' "least_col"=LEAST("test_upsert_with_functions"."least_col", EXCLUDED."least_col"),'
. ' "longest_col"=(SELECT value FROM (SELECT "test_upsert_with_functions"."longest_col" AS value UNION SELECT EXCLUDED."longest_col" AS value) AS t ORDER BY LENGTH(value) DESC LIMIT 1),'
. ' "shortest_col"=(SELECT value FROM (SELECT "test_upsert_with_functions"."shortest_col" AS value UNION SELECT EXCLUDED."shortest_col" AS value) AS t ORDER BY LENGTH(value) ASC LIMIT 1)';

$data[0][4]['array_col'] = '{1,2,3,4,5}';
$data[0][5] = [
':qp0' => new Param('short', DataType::STRING),
':qp1' => new Param('short', DataType::STRING),
];

return $data;
}
}
12 changes: 12 additions & 0 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -653,4 +653,16 @@ public function testArrayMergeWithTypeWithOrdering(

$this->assertSame($expectedResult, $result);
}

#[DataProviderExternal(QueryBuilderProvider::class, 'upsertWithMultiOperandFunctions')]
public function testUpsertWithMultiOperandFunctions(
array $initValues,
array $insertValues,
array $updateValues,
string $expectedSql,
array $expectedResult,
array $expectedParams = [],
): void {
parent::testUpsertWithMultiOperandFunctions($initValues, $insertValues, $updateValues, $expectedSql, $expectedResult, $expectedParams);
}
}