Skip to content

Commit

Permalink
PostgreReflector: fix autoincrement column detection
Browse files Browse the repository at this point in the history
  • Loading branch information
JanRossler authored and dg committed Nov 5, 2023
1 parent 6cc7ce8 commit beba7b3
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions src/Dibi/Drivers/PostgreReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ public function getTables(): array
public function getColumns(string $table): array
{
$_table = $this->driver->escapeText($this->driver->escapeIdentifier($table));
$res = $this->driver->query("
SELECT indkey
FROM pg_class
LEFT JOIN pg_index on pg_class.oid = pg_index.indrelid AND pg_index.indisprimary
WHERE pg_class.oid = $_table::regclass
");
$primary = (int) $res->fetch(true)['indkey'];

$res = $this->driver->query("
SELECT *
Expand Down Expand Up @@ -123,7 +116,7 @@ public function getColumns(string $table): array
'size' => $size > 0 ? $size : null,
'nullable' => $row['is_nullable'] === 'YES' || $row['is_nullable'] === 't' || $row['is_nullable'] === true,
'default' => $row['column_default'],
'autoincrement' => (int) $row['ordinal_position'] === $primary && str_starts_with($row['column_default'] ?? '', 'nextval'),
'autoincrement' => str_starts_with($row['column_default'] ?? '', 'nextval('),
'vendor' => $row,
];
}
Expand Down

0 comments on commit beba7b3

Please sign in to comment.