The query looks harmless and it should work in oracle or postgresql if the data-model installed correctly.
Try checking to see if the apm_package_versions table exists from psql:
openacs45=# \d apm_package_versions
And then try running the query from psql:
openacs45=# select case when count(*) = 0 then 0 else 1 end from apm_package_versions;
case
------
1
(1 row)
You'll probably find that something is not installed correctly.