Removing usage of temp table pgd_all_data.
This required restructuring things into a big COPY statement operating on a series of
UNION ALL subqueries, from the previous form of inserting multiple times into the temp table