-
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SEARCH-359 adjunct: create a view for area containments, use in Data:…
…:Area
- Loading branch information
1 parent
7533a97
commit 04a436e
Showing
7 changed files
with
99 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
\set ON_ERROR_STOP 1 | ||
|
||
BEGIN; | ||
|
||
-- First, construct a table (recursively) of parent -> descendant connections | ||
-- for areas, including an array of the path (the 'descendants' array). | ||
|
||
-- Then, find the shortest path to each type of parent by joining to area, | ||
-- distinct on descendant, type, and order by the length of the array of descendants. | ||
CREATE OR REPLACE VIEW area_containment AS | ||
WITH RECURSIVE area_descendants AS ( | ||
SELECT entity0 AS parent, entity1 AS descendant, ARRAY[entity1] AS descendants | ||
FROM l_area_area laa | ||
JOIN link ON laa.link = link.id | ||
JOIN link_type ON link.link_type = link_type.id | ||
WHERE link_type.gid = 'de7cc874-8b1b-3a05-8272-f3834c968fb7' | ||
UNION ALL | ||
SELECT entity0 AS parent, descendant, descendants || entity1 | ||
FROM l_area_area laa | ||
JOIN link ON laa.link=link.id | ||
JOIN link_type ON link.link_type = link_type.id | ||
JOIN area_descendants ON area_descendants.parent = laa.entity1 | ||
WHERE link_type.gid = 'de7cc874-8b1b-3a05-8272-f3834c968fb7' | ||
AND NOT entity0 = ANY(descendants)) | ||
SELECT DISTINCT ON (descendant, type) descendant, area_descendants.parent, area.type, area_type.name AS type_name, descendants || area_descendants.parent AS descendant_hierarchy | ||
FROM area_descendants | ||
JOIN area ON area_descendants.parent = area.id | ||
JOIN area_type ON area.type = area_type.id | ||
WHERE area.type IN (1, 2, 3) | ||
ORDER BY descendant, type, array_length(descendants, 1) ASC; | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"20": { | ||
"slave": ["20140310-dates.sql", "20140212-ordering-columns.sql", "20140208-drop-script_language.sql", "20140407-link-cardinality.sql", "20140311-remove-area-sortnames.sql", "20140313-remove-label-sortnames.sql", "20140214-add-instruments.sql", "20140215-add-instruments-documentation.sql", "20140318-series.sql", "20140418-series-instrument-functions.sql"], | ||
"slave": ["20140310-dates.sql", "20140212-ordering-columns.sql", "20140208-drop-script_language.sql", "20140407-link-cardinality.sql", "20140311-remove-area-sortnames.sql", "20140313-remove-label-sortnames.sql", "20140214-add-instruments.sql", "20140215-add-instruments-documentation.sql", "20140318-series.sql", "20140418-series-instrument-functions.sql", "20140429-area-view.sql"], | ||
"standalone": ["20140308-ordering-columns-fk.sql", "20140312-dates-trigger.sql", "20140217-instrument-triggers.sql", "20140318-series-fks.sql"] | ||
} | ||
} |