我有一个巨大的Firebird数据库,其中有一个表,其中有4100万行数据。最近,我添加了一个新的浮点列,并希望用增量数据填充它。每个下一个值都应该是由RAND()递增的前一个值。第一个值也是RAND()。
该怎么做呢?
查询
SELECT ID FROM MY_TABLE WHERE MY_COLUMN IS NULL ROWS 1;最多需要15秒,所以我不会指望这个查询会在循环中执行。
该表有一个索引ID列,它是复合主键的一部分。
发布于 2017-06-29 20:24:45
就像这样
update MyTable set MyColumn = Gen_ID( TempGen,
round( rand() * 100000) ) / 100000.0或者使用存储过程或执行块
就像这样
execute block
as
declare f double precision = 0;
declare i int;
begin
for select ID FROM MY_TABLE WHERE MY_COLUMN IS NULL order by id into :I
do begin
f = f + rand();
update MY_TABLE SET MY_COLUMN = :f where ID = :i;
end;
end或者您可以尝试使用游标,但我没有尝试,所以我不确定它是如何工作的。
https://www.firebirdsql.org/refdocs/langrefupd25-psql-forselect.html
execute block
as
declare f double precision = 0;
begin
for select ID FROM MY_TABLE WHERE MY_COLUMN IS NULL order by id
as cursor C do begin
f = f + rand();
update MY_TABLE SET MY_COLUMN = :f where current of C;
end;
endhttps://stackoverflow.com/questions/44824177
复制相似问题