Return records from exposure functions

Refactor existing exposure CSV generation code into smaller functions which return records and which can be used in VIEWS and from other functions.

Also replace temporary table with  "WITH " query to permit use from read-only connections (e.g. from QGIS)