{"record":{"id":"fa50c5786f500246","repo":"ankane/pgsync","slug":"primary-key-required-for-in-batches","errorCode":null,"errorMessage":"Primary key required for --in-batches","messagePattern":"Primary key required for --in-batches","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/pgsync/task.rb","lineNumber":91,"sourceCode":"        notes << \"Different column types: #{different_types.join(\", \")}\" if different_types.any?\n      end\n      notes\n    end\n\n    def sync_data\n      raise Error, \"This should never happen. Please file a bug.\" if shared_fields.empty?\n\n      sql_clause = String.new(\"\")\n      sql_clause << \" #{opts[:sql]}\" if opts[:sql]\n\n      bad_fields = opts[:no_rules] ? [] : config[\"data_rules\"]\n      primary_key = to_primary_key\n      copy_fields = shared_fields.map { |f| f2 = bad_fields.to_a.find { |bf, _| rule_match?(table, f, bf) }; f2 ? \"#{apply_strategy(f2[1], table, f, primary_key)} AS #{quote_ident(f)}\" : \"#{quoted_table}.#{quote_ident(f)}\" }.join(\", \")\n      fields = shared_fields.map { |f| quote_ident(f) }.join(\", \")\n\n      copy_to_command = \"COPY (SELECT #{copy_fields} FROM #{quoted_table}#{sql_clause}) TO STDOUT\"\n      if opts[:in_batches]\n        raise Error, \"Primary key required for --in-batches\" if primary_key.empty?\n        primary_key = primary_key.first\n\n        destination.truncate(table) if opts[:truncate]\n\n        from_max_id = source.max_id(table, primary_key)\n        to_max_id = destination.max_id(table, primary_key) + 1\n\n        if to_max_id == 1\n          from_min_id = source.min_id(table, primary_key)\n          to_max_id = from_min_id if from_min_id > 0\n        end\n\n        starting_id = to_max_id\n        batch_size = opts[:batch_size]\n\n        i = 1\n        batch_count = ((from_max_id - starting_id + 1) / batch_size.to_f).ceil\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/ankane/pgsync/blob/57bdddf5db506d329b51cb3376379dc3a2559010/lib/pgsync/task.rb#L73-L109","documentation":"Error \"Primary key required for --in-batches\" thrown in ankane/pgsync.","triggerScenarios":"Thrown at lib/pgsync/task.rb:91 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"57bdddf5db506d329b51cb3376379dc3a2559010","analyzedAt":"2026-08-23T11:18:48.887Z","schemaVersion":2},"datasetVersion":"2026-08-23T16:17:53.355Z"}