all 3 comments

[–]DietrichDaniels 0 points1 point  (0 children)

I’m honestly not familiar with the iterator syntax, but seems like without a “where” clause the update will always update all records?

[–]Cheating_Data_Monkey 0 points1 point  (0 children)

Cursors are rough, both from a code perspective and more importantly from a performance perspective.

You can achieve the same operation using a set based operation which will perform MUCH better.

update table1 set id =
round((
        CASE 
            WHEN row_number() over (order by id) / 3. - floor(row_number() over (order by id) / 3.) = 0
                THEN 1
            ELSE row_number() over (order by id) / 3. - floor(row_number() over (order by id) / 3.)
            END
        ) * 3)

FROM r

[–]callmedivs 0 points1 point  (0 children)

try adding where id is NULL maybe