我需要向我的PostgreSQL(v9.5)表中插入大量的行。
下面是表格:
create table TaskLog(
id serial,
taskid integer,
x double precision,
y double precision,
loc character varying(50),
speed smallint,
gpstime timestamp without time zone,
veh character varying(16),
vin character(17),
regdate date,
enabled boolean,
remake character varying(100),
isdel boolean,
alarm integer,
CONSTRAINT pk_delphi_id PRIMARY KEY (id)
)
字符串
我使用FireDAC( Delphi XE10.1)插入行:
function RandomStr(aLength : Integer) : string;
var
X: Integer;
begin
if aLength <= 0 then exit;
SetLength(Result, aLength);
for X:=1 to aLength do
Result[X] := Chr(Random(26) + 65);
end;
procedure TForm7.Button6Click(Sender: TObject);
var
i: Integer;
Watch: TStopwatch;
begin
Watch := TStopwatch.StartNew;
try
FDQuery1.SQL.Text :=
'insert into TaskLog values(default, :f1, :f2, :f3, :f4, :f5, :f6, ' +
':f7, :f8, :f9, :f10, :f11, :f12, :f13)';
FDQuery1.Params.ArraySize := StrToInt(Edit1.text); //<--- Change the ArraySize
for i := 0 to FDQuery1.Params.ArraySize - 1 do
begin
FDQuery1.Params[0].AsIntegers[i] := Random(9999999);
FDQuery1.Params[1].AsFloats[i] := Random(114) + Random;
FDQuery1.Params[2].AsFloats[i] := Random(90) + Random;
FDQuery1.Params[3].AsStrings[i] := RandomStr(Random(50));
FDQuery1.Params[4].AsSmallInts[i] := Random(1990);
FDQuery1.Params[5].AsDateTimes[i] := IncSecond(IncDay(Now, -(Random(100) + 1)), Random(99999));
FDQuery1.Params[6].AsStrings[i] := RandomStr(Random(16));
FDQuery1.Params[7].AsStrings[i] := RandomStr(Random(17));
FDQuery1.Params[8].AsDates[i] := IncDay(Now, -(Random(365) + 1));
FDQuery1.Params[9].AsBooleans[i] := Odd(Random(200));
FDQuery1.Params[10].AsStrings[i] := RandomStr(Random(100));
FDQuery1.Params[11].AsBooleans[i] := Odd(Random(100));
FDQuery1.Params[12].AsIntegers[i] := Random(100000);
end;
FDQuery1.Execute(FDQuery1.Params.ArraySize);
Watch.Stop;
Memo1.Lines.Add('Should be inserted ' + IntToStr(FDQuery1.Params.ArraySize) + ' lines');
Memo1.Lines.Add('Actually inserted ' + IntToStr(FDQuery1.RowsAffected) + ' lines');
Memo1.Lines.Add('Take ' + Watch.ElapsedMilliseconds.ToString + ' seconds');
except
Memo1.Lines.Add(Exception(ExceptObject).Message);
end;
end;
型
当我设置FDQuery1.Params.ArraySize:=1000
时,它工作正常,当我设置FDQuery1.Params.ArraySize:=10000
时,它失败了,没有记录可以插入。
ArraySize属性在PostgreSQL中有大小限制吗?
1条答案
按热度按时间eufgjt7s1#
字符串
服务器端SQL:输入propose_sid VALUES(DEFAULT,$1,$2,$3,$4,$5,$6,$7,$8),(DEFAULT,$9,$10,$11,$12,$13,$14,$15,$16),(DEFAULT,$17,$18,$19,$20,$21,$22,$23,$24). -- 1999 times