1
SELECT facilities.id AS facility_id,
2
facilities.name AS facility_name,
3
facilities.facility_type,
4
facilities.facility_size,
5
facility_regions.id AS facility_region_id,
6
facility_regions.name AS facility_region_name,
7
facility_regions.slug AS facility_region_slug,
8
block_regions.id AS block_region_id,
9
block_regions.name AS block_name,
10
block_regions.slug AS block_slug,
11
district_regions.source_id AS district_id,
12
district_regions.id AS district_region_id,
13
district_regions.name AS district_name,
14
district_regions.slug AS district_slug,
15
state_regions.id AS state_region_id,
16
state_regions.name AS state_name,
17
state_regions.slug AS state_slug,
18
org_regions.source_id AS organization_id,
19
org_regions.id AS organization_region_id,
20
org_regions.name AS organization_name,
21
org_regions.slug AS organization_slug
22
FROM (((((regions facility_regions
23
JOIN facilities ON ((facilities.id = facility_regions.source_id)))
24
JOIN regions block_regions ON ((block_regions.path = subpath(facility_regions.path, 0, '-1'::integer))))
25
JOIN regions district_regions ON ((district_regions.path = subpath(block_regions.path, 0, '-1'::integer))))
26
JOIN regions state_regions ON ((state_regions.path = subpath(district_regions.path, 0, '-1'::integer))))
27
JOIN regions org_regions ON ((org_regions.path = subpath(state_regions.path, 0, '-1'::integer))))
28
WHERE ((facility_regions.region_type)::text = 'facility'::text);