diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb index 7d6aba9daf835..06b4658b78efe 100644 --- a/activerecord/lib/active_record/model_schema.rb +++ b/activerecord/lib/active_record/model_schema.rb @@ -435,8 +435,12 @@ def columns def _returning_columns_for_insert(connection) # :nodoc: @_returning_columns_for_insert ||= begin - auto_populated_columns = columns.filter_map do |c| - c.name if connection.return_value_after_insert?(c) + auto_populated_columns = if connection.supports_insert_returning? + columns.filter_map do |c| + c.name if connection.return_value_after_insert?(c) + end + else # we shouldn't be trying to build a list of returning columns if db doesn't `RETURNING` statement + [] end auto_populated_columns.empty? ? Array(primary_key) : auto_populated_columns