ankane/pgsync · error · Error
Primary key required for --in-batches
Error message
Primary key required for --in-batches
What it means
Error "Primary key required for --in-batches" thrown in ankane/pgsync.
Source
Thrown at lib/pgsync/task.rb:91
notes << "Different column types: #{different_types.join(", ")}" if different_types.any?
end
notes
end
def sync_data
raise Error, "This should never happen. Please file a bug." if shared_fields.empty?
sql_clause = String.new("")
sql_clause << " #{opts[:sql]}" if opts[:sql]
bad_fields = opts[:no_rules] ? [] : config["data_rules"]
primary_key = to_primary_key
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(", ")
fields = shared_fields.map { |f| quote_ident(f) }.join(", ")
copy_to_command = "COPY (SELECT #{copy_fields} FROM #{quoted_table}#{sql_clause}) TO STDOUT"
if opts[:in_batches]
raise Error, "Primary key required for --in-batches" if primary_key.empty?
primary_key = primary_key.first
destination.truncate(table) if opts[:truncate]
from_max_id = source.max_id(table, primary_key)
to_max_id = destination.max_id(table, primary_key) + 1
if to_max_id == 1
from_min_id = source.min_id(table, primary_key)
to_max_id = from_min_id if from_min_id > 0
end
starting_id = to_max_id
batch_size = opts[:batch_size]
i = 1
batch_count = ((from_max_id - starting_id + 1) / batch_size.to_f).ceil
View on GitHub (pinned to 57bdddf5db)
When it happens
Trigger: Thrown at lib/pgsync/task.rb:91 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of ankane/pgsync@57bdddf5db (2026-08-23).
Data as JSON: /api/errors/fa50c5786f500246.
Report an issue: GitHub.