开始...每50行提交一次

开始...每50行提交一次

问题描述:

我有一个500,000行的sql脚本。

I have a 500,000 line sql script.

update users set region_id = 9814746 where id = 101 and region_id is null;
update users set region_id = 9814731 where id = 102 and region_id is null;
update users set region_id = 3470676 where id = 103 and region_id is null;
...
....

我需要生成一个带有begin ...的脚本,每50行提交一次。
我该怎么做?
我将在pg-admin中运行它。

I need to be able to generate a script with begin...commit every 50 lines. How do I do this? I'll be running this in pg-admin.

谢谢,
Sharadov

Thanks, Sharadov

这可能是一个不错的开始:

cat sql.file | perl -e’i = 0;打印 begin; \n; while(<>){print; i ++; if(i%50 == 0){print end; \nbegin; \n;}} print end\n;’ outputsql.file

This might be a good start:
cat sql.file | perl -e 'i=0;print "begin;\n"; while(<>){print;i++;if(i % 50 == 0){print "end;\nbegin;\n";}}print "end\n";' > outputsql.file