Skip to content

Commit

Permalink
Support using no_auto_parameterize to remove the insert limit
Browse files Browse the repository at this point in the history
Before this change, if you enabled the pg_auto_parameterize extension,
all inserts were limited to 40 rows at a time.

Now, you can use the `#no_auto_parameterize` method to turn off this
behavior since inserts without parameterization can handle much higher
rows at a time.
  • Loading branch information
davekaro committed Nov 4, 2024
1 parent 865d985 commit 2df2aad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sequel/extensions/pg_auto_parameterize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def auto_param?(sql)
# there can be more than one parameter per column, so this doesn't prevent going
# over the limit, though it does make it less likely.
def default_import_slice
40
@opts[:no_auto_parameterize] ? super : 40
end

# Handle parameterization of multi_insert_sql
Expand Down
8 changes: 8 additions & 0 deletions spec/extensions/pg_auto_parameterize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ def copy_table_sql(ds, *) "COPY TABLE #{ds.is_a?(Sequel::Dataset) ? ds.sql : ds}
sqls[1].must_equal 'INSERT INTO "table" ("a") VALUES ' + args[0...40].map{|i| "($#{i}::int4)"}.join(', ') + " -- args: #{args[40...80].inspect}"
end

it "should not split inserts of multiple rows to 40 at a time with no_auto_parameterize" do
args = (1...81).to_a
@db[:table].no_auto_parameterize.import([:a], args)
sqls = @db.sqls
sqls.size.must_equal 1
sqls[0].must_equal 'INSERT INTO "table" ("a") VALUES ' + args.map{|i| "(#{i})"}.join(', ')
end

it "should automatically parameterize queries strings, blobs, numerics, dates, and times" do
ds = @db[:table]
pr = proc do |sql, *args|
Expand Down

0 comments on commit 2df2aad

Please sign in to comment.