Richard Huxton <dev(at)archonet(dot)com> writes:
> I think the problem is you're missing the "END IF" from all the intermediate
> IFs. I don't think there actually is an "ELSEIF" structure, it's just an ELSE
> followed by an IF, so the IF needs to be concluded as normal.
Recent releases (at least 7.2 and later) have an ELSIF abbrevation too.
See
http://www.ca.postgresql.org/users-lounge/docs/7.2/postgres/plpgsql-control-structures.html
regards, tom lane