@@ -1137,17 +1137,34 @@ public function pkAndSequenceFor($table)
1137
1137
1138
1138
if (!$ result ) {
1139
1139
$ sql = "
1140
- SELECT c.column_name, c.ordinal_position,
1141
- pg_get_serial_sequence(t.table_name, c.column_name) as relname
1140
+ SELECT c.column_name as attname, c.ordinal_position,
1141
+ pg_get_serial_sequence(t.table_name, c.column_name) as relname,
1142
+ col.data_type
1142
1143
FROM information_schema.key_column_usage AS c
1143
1144
LEFT JOIN information_schema.table_constraints AS t
1144
1145
ON t.constraint_name = c.constraint_name
1146
+ LEFT JOIN information_schema.columns AS col
1147
+ ON col.table_name = t.table_name
1148
+ AND col.column_name = c.column_name
1145
1149
WHERE t.table_name = ' $ table' AND t.constraint_type = 'PRIMARY KEY'; " ;
1146
- $ result = $ this ->adapter ->selectOne ($ sql , 'PK and custom sequence ' );
1150
+ $ results = $ this ->selectAll ($ sql , 'PK and custom sequence ' );
1151
+
1152
+ // Return null if no results or multiple rows
1153
+ // (multiple rows means composite PK with multiple columns where autoincrement is not supported )
1154
+ if (!$ results || count ($ results ) > 1 ) {
1155
+ return array (null , null );
1156
+ }
1157
+
1158
+ $ result = $ results [0 ];
1147
1159
}
1148
1160
1149
- if (!$ result ) {
1150
- return array (null , null );
1161
+ // Only warn about missing sequences for plain integer primary keys
1162
+ if (isset ($ result ['data_type ' ]) &&
1163
+ (strpos ($ result ['data_type ' ], 'int ' ) !== false ||
1164
+ strpos ($ result ['data_type ' ], 'serial ' ) !== false )) {
1165
+ if ($ this ->_logger && !$ result ['relname ' ]) {
1166
+ $ this ->_logger ->warn (sprintf ('%s has Primary key %s with no default sequence ' , $ table , $ result ['attname ' ]));
1167
+ }
1151
1168
}
1152
1169
1153
1170
// [primary_key, sequence]
0 commit comments