> > insert into mytable2 select * from mytable1 order by ctid limit 10_000_000 > offset 20_000_000; >
You can use min/max values grouping them by 10_000_000 records, so you donĀ“t need that offset, then generate commands and run them. select format('insert into mytable2 select * from mytable1 where i between %s and %s;', max(i), min(i)) from t group by i/10_000_000;