         ELSE NULL::INTEGER
     END AS dw_contact_events_id,
     pl.name AS name,
-    c.code_description AS place_type,
+    pt.place_types AS place_type,
     pl.id AS place_id
 FROM
     events

    LEFT JOIN dw_entity_telephones repag_phn
        ON (repag_phn.entity_id = repagpart.secondary_entity_id)
    LEFT JOIN (
        SELECT DISTINCT ON (place_id) place_id, type_id FROM places_types
    ) repagpt
        ON (repagpt.place_id = repagpl.id)
    LEFT JOIN codes repagc
        ON (repagc.id = repagpt.type_id AND repagc.deleted_at IS NULL)
    LEFT JOIN (
        SELECT
            a.event_id,

    LEFT JOIN places
        ON (places.entity_id = p.secondary_entity_id)
    LEFT JOIN (
        SELECT place_id, trisano.text_join_agg(code_description, ', ') AS place_types
        FROM
            codes
            JOIN places_types
                ON (places_types.type_id = codes.id)
        GROUP BY place_id 
    ) pt
        ON (pt.place_id = places.id)
--    LEFT JOIN codes repagc
--        ON (repagc.id = repagpt.type_id AND repagc.deleted_at IS NULL)
--    LEFT JOIN (
--        -- Just in case there are places with multiple types. We only want it to create one record
--        SELECT DISTINCT ON (place_id) place_id, type_id FROM places_types
--    ) pt
--        ON (pt.place_id = places.id)
--    LEFT JOIN codes c
--        ON (c.id = pt.type_id AND c.deleted_at IS NULL)
    LEFT JOIN organisms org
        ON (org.id = lr.organism_id)
;
