Skip to content

Commit 7ca4750

Browse files
JanRosslerdg
authored andcommitted
PostgreReflector: detect IDENTITY columns as autoincrement
1 parent beba7b3 commit 7ca4750

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Dibi/Drivers/PostgreReflector.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public function getColumns(string $table): array
9191
a.atttypmod-4 AS character_maximum_length,
9292
NOT a.attnotnull AS is_nullable,
9393
a.attnum AS ordinal_position,
94-
pg_get_expr(adef.adbin, adef.adrelid) AS column_default
94+
pg_get_expr(adef.adbin, adef.adrelid) AS column_default,
95+
CASE WHEN a.attidentity IN ('a', 'd') THEN 'YES' ELSE 'NO' END AS is_identity
9596
FROM
9697
pg_attribute a
9798
JOIN pg_type ON a.atttypid = pg_type.oid
@@ -116,7 +117,7 @@ public function getColumns(string $table): array
116117
'size' => $size > 0 ? $size : null,
117118
'nullable' => $row['is_nullable'] === 'YES' || $row['is_nullable'] === 't' || $row['is_nullable'] === true,
118119
'default' => $row['column_default'],
119-
'autoincrement' => str_starts_with($row['column_default'] ?? '', 'nextval('),
120+
'autoincrement' => $row['is_identity'] === 'YES' || str_starts_with($row['column_default'] ?? '', 'nextval('),
120121
'vendor' => $row,
121122
];
122123
}

0 commit comments

Comments
 (0)