core: fixing PG 8.4 compatability

Since FOREACH is supported only for PG 9.x the following script uses the
unnest functions instead.

Change-Id: I19cabe0b559abc8e505ce8712065a147631fd75e
Signed-off-by: Eli Mesika <emesika@redhat.com>