Skip to content

Commit c46a1de

Browse files
diegosardinaMiloslav Hůla
authored andcommitted
Added support to PostgreSQL identity column (#227)
1 parent 1cc820e commit c46a1de

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/Database/Drivers/PgSqlDriver.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,15 @@ public function getColumns(string $table): array
135135
CASE WHEN a.atttypmod = -1 THEN NULL ELSE a.atttypmod -4 END AS size,
136136
NOT (a.attnotnull OR t.typtype = 'd' AND t.typnotnull) AS nullable,
137137
pg_catalog.pg_get_expr(ad.adbin, 'pg_catalog.pg_attrdef'::regclass)::varchar AS default,
138-
coalesce(co.contype = 'p' AND strpos(pg_catalog.pg_get_expr(ad.adbin, ad.adrelid), 'nextval') = 1, FALSE) AS autoincrement,
138+
coalesce(co.contype = 'p' AND (seq.relname IS NOT NULL OR strpos(pg_catalog.pg_get_expr(ad.adbin, ad.adrelid), 'nextval') = 1), FALSE) AS autoincrement,
139139
coalesce(co.contype = 'p', FALSE) AS primary,
140-
substring(pg_catalog.pg_get_expr(ad.adbin, 'pg_catalog.pg_attrdef'::regclass) from 'nextval[(]''\"?([^''\"]+)') AS sequence
140+
coalesce(seq.relname, substring(pg_catalog.pg_get_expr(ad.adbin, 'pg_catalog.pg_attrdef'::regclass) from 'nextval[(]''\"?([^''\"]+)')) AS sequence
141141
FROM
142142
pg_catalog.pg_attribute AS a
143143
JOIN pg_catalog.pg_class AS c ON a.attrelid = c.oid
144144
JOIN pg_catalog.pg_type AS t ON a.atttypid = t.oid
145+
LEFT JOIN pg_catalog.pg_depend AS d ON d.refobjid = c.oid AND d.refobjsubid = a.attnum AND d.deptype = 'i'
146+
LEFT JOIN pg_catalog.pg_class AS seq ON seq.oid = d.objid AND seq.relkind = 'S'
145147
LEFT JOIN pg_catalog.pg_attrdef AS ad ON ad.adrelid = c.oid AND ad.adnum = a.attnum
146148
LEFT JOIN pg_catalog.pg_constraint AS co ON co.connamespace = c.relnamespace AND contype = 'p' AND co.conrelid = c.oid AND a.attnum = ANY(co.conkey)
147149
WHERE

0 commit comments

Comments
 (0)