Can I make this UPDATE faster? I got this code (python - psycopg2) which takes about 2 minutes to complete. I need each row (60 rows) in each column (288 columns) to get the value from its following column (and corresponding row). Is there any SQL trick to make it happen faster?

for i in range(1, 288):
    oy = i + 1
    for izi in range(1, 61):
        cur.execute("UPDATE d2 SET stav_" + str(i) + " = (SELECT stav_" + str(oy) + " FROM d2 WHERE usek = " + str(izi) + ") WHERE usek = " + str(izi) + ";")
        conn.commit()
You are running 17568 updates (and 17568 selects) for something that can be done with a single statement:

update d2
   set stav_1 = stav_2, 
       stav_2 = stav_3, 
       stav_3 = stav_4, 
       ....
where usek between 1 and 61;
commit;


If you don't want to type 288 column names, then use your program to generate the above statement and execute that once. 



Having numbered columns is very often a sign of a bad data model. The need to "move" values from one column to another is another sign that you should really re-design your data model and normalize it.