Skip to content

Commit

Permalink
PostgreReflector: detect IDENTITY columns as autoincrement
Browse files Browse the repository at this point in the history
  • Loading branch information
JanRossler authored and dg committed Nov 5, 2023
1 parent beba7b3 commit 7ca4750
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Dibi/Drivers/PostgreReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public function getColumns(string $table): array
a.atttypmod-4 AS character_maximum_length,
NOT a.attnotnull AS is_nullable,
a.attnum AS ordinal_position,
pg_get_expr(adef.adbin, adef.adrelid) AS column_default
pg_get_expr(adef.adbin, adef.adrelid) AS column_default,
CASE WHEN a.attidentity IN ('a', 'd') THEN 'YES' ELSE 'NO' END AS is_identity
FROM
pg_attribute a
JOIN pg_type ON a.atttypid = pg_type.oid
Expand All @@ -116,7 +117,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' => str_starts_with($row['column_default'] ?? '', 'nextval('),
'autoincrement' => $row['is_identity'] === 'YES' || str_starts_with($row['column_default'] ?? '', 'nextval('),
'vendor' => $row,
];
}
Expand Down

0 comments on commit 7ca4750

Please sign in to comment.