使用随机值填充数字列

时间:2016-06-09 12:32:49

标签: sql postgresql random

这是我的表:resize()

我这样做是为了填充它:

update AEROPORTO.RESERVA 
   set VALOR = random()*(5000-1500)+1500
where cod_reserva is not null

但是random()具有双精度,我的价值观是这样的:

  • 111,11
  • 222,22

round()不使用双精度。

我试图改变Valor字段的数据类型,但没有奏效。尝试过数字,货币和浮动。

我需要运行一个脚本,该字段只用2位精度随机填充此字段。

1 个答案:

答案 0 :(得分:0)

有两个round个函数,round(dp or numeric)返回整数,round(v numeric, s int)返回numeric。请尝试以下方法:

update AEROPORTO.RESERVA 
   set VALOR = round((random()*(5000-1500)+1500)::numeric, 2)
where cod_reserva is not null