Instead of running that big, complicated query I decided to use some more advanced features of postgresql and handle things a little differently.
I added two new columns to the forums table:
ALTER TABLE myforum_forums ADD COLUMN postcount INT;
ALTER TABLE myforum_forums ALTER postcount SET DEFAULT 0;
ALTER TABLE myforum_forums ADD COLUMN threadcount INT;
ALTER TABLE myforum_forums ALTER threadcount SET DEFAULT 0;
then update existing rows:
UPDATE myforum_forums SET postcount=0, threadcount=0;
Then we do the same for threads:
ALTER TABLE myforum_threads ADD COLUMN postcount INT;
ALTER TABLE myforum_threads ALTER postcount SET DEFAULT 0;
UPDATE myforum_threads SET postcount=0;
Postgresql currently doesn't let you add a field to a table and set a default at the same time, but this is easy to overcome as you can see by running the two steps separately. This functionality may become available in future versions, but since it can easily be done in two stages, there won't be a huge need for it. See
alter documentation for more info.