unnest
यह सब एक साथ बनाने के लिए डेटा:
def create_random(i):
return random() * i
curs.execute("select gid, number from t;")
data = curs.fetchall()
results = []
for i in data:
results.append((create_random(i[1]), i[0]))
curs.execute("""
update t
set
rnd = s.rnd,
result = number * s.rnd
from unnest(%s) s(rnd numeric, gid integer)
where t.gid = s.gid;
""", (results,))
con.commit()
टेबल टी:
create table t (
gid integer,
number integer,
rnd float,
result float
);