From 7ca47508cb10f70c52204f2ace332fa61839c15c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20R=C3=B6ssler?= Date: Sat, 9 Apr 2022 18:11:20 +0200 Subject: [PATCH] PostgreReflector: detect IDENTITY columns as autoincrement --- src/Dibi/Drivers/PostgreReflector.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Dibi/Drivers/PostgreReflector.php b/src/Dibi/Drivers/PostgreReflector.php index 8eae9856..29a33c15 100644 --- a/src/Dibi/Drivers/PostgreReflector.php +++ b/src/Dibi/Drivers/PostgreReflector.php @@ -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 @@ -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, ]; }