Wed Feb 29 10:04:32 EST 2012

Database cursors

So I've done queries 101 (data filtering), next is updates (for
loops / database cursors).

I want to run an UPDATE procedure for all the results in a SELECT.

Looks like this is possible within the UPDATE clause itself:

  UPDATE table
  SET column = value, ...
  WHERE ...

Though that does an iteration over the table itself (the iterated
table is the same as the updated one).  That's not what I want.  I
want to iterate over table1 and insert/update values in table2.

  for rec in table1; do
     if predicate(rec); then
         replace(table2, field, "value")