vendredi 20 décembre 2019

Looping inside a Postgres UPDATE query

(Postgres 10.10) I have the following fields in my_table:

loval INTEGER 
hival INTEGER 
valcount INTEGER 
values INTEGER[]

I need to set values to an array containing valcount random integers each between loval and hival inclusive. So for:

loval: 3 
hival: 22 
valcount: 6

I'm looking to set values to something like:

{3, 6, 6, 13, 17, 22}

I know how to do this with an inefficient "loop through the cursor" solution, but I'm wondering if Postgres has a way to do a looping computation inline.

Note: I looked at generate_series, but I don't think it produces what I need.




Aucun commentaire:

Enregistrer un commentaire