Skip to content

Commit af86a96

Browse files
authored
Merge pull request #9014 from sbulen/30_pg_data_population
[3.0] Fix key identification to address data population
2 parents 0e0d007 + af9acb0 commit af86a96

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

Sources/Db/APIs/PostgreSQL.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -411,21 +411,13 @@ public function insert(string $method, string $table, array $columns, array $dat
411411

412412
// PostgreSQL doesn't support replace: we implement a MySQL-compatible behavior instead
413413
if ($method == 'replace' || $method == 'ignore') {
414-
$key_str = '';
414+
$key_str = implode(',', $keys);
415415
$col_str = '';
416-
417416
$count = 0;
418-
$count_pk = 0;
419417

418+
// Make a list of the non-pk fields.
420419
foreach ($columns as $columnName => $type) {
421-
// Check pk field.
422-
if (\in_array($columnName, $keys)) {
423-
$key_str .= ($count_pk > 0 ? ',' : '');
424-
$key_str .= $columnName;
425-
$count_pk++;
426-
}
427-
// Normal field.
428-
elseif ($method == 'replace') {
420+
if (!\in_array($columnName, $keys) && ($method == 'replace')) {
429421
$col_str .= ($count > 0 ? ',' : '');
430422
$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
431423
$count++;

Sources/Db/Schema/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ public function populate(bool $replace = false): int
547547
table: '{db_prefix}' . $this->name,
548548
columns: Db::$db->getTypeIndicators('{db_prefix}' . $this->name, reset($this->initial_data)),
549549
data: array_map(fn($row) => array_values($row), $this->initial_data),
550-
keys: isset($auto_col) ? [$auto_col] : [],
550+
keys: isset($auto_col) ? [$auto_col] : array_column($this->indexes['primary']->columns, 'name'),
551551
returnmode: $returnmode,
552552
);
553553

0 commit comments

Comments
 (0)