Revision 4519
Added by Aaron Marcuse-Kubitza over 12 years ago
inputs/VegBank/vegbank.~.utils.sql | ||
---|---|---|
1 |
-- Function: "VegBank".plantconcept_ancestors(integer) |
|
2 |
|
|
3 |
-- DROP FUNCTION "VegBank".plantconcept_ancestors(integer); |
|
4 |
|
|
5 |
CREATE OR REPLACE FUNCTION "VegBank".plantconcept_ancestors(IN plantconcept_id_ integer, OUT ancestor_id integer, OUT plantlevel character varying) |
|
6 |
RETURNS SETOF record AS |
|
7 |
$BODY$ |
|
8 |
DECLARE |
|
9 |
plantparent_id "VegBank".plantstatus.plantparent_id%TYPE; |
|
10 |
BEGIN |
|
11 |
-- Get plantparent_id. Remove plantconcept_id if no match or no plantstatus. |
|
12 |
SELECT plantconcept_id, plantstatus.plantlevel, plantstatus.plantparent_id |
|
13 |
INTO ancestor_id, plantlevel, plantparent_id |
|
14 |
FROM "VegBank".plantstatus |
|
15 |
WHERE plantconcept_id = plantconcept_id_ |
|
16 |
; |
|
17 |
-- Add this level to the list (output params' current values) |
|
18 |
RETURN NEXT; |
|
19 |
-- Recurse |
|
20 |
IF plantparent_id IS NOT NULL THEN |
|
21 |
RETURN QUERY ( |
|
22 |
SELECT * FROM "VegBank"."plantconcept_ancestors"(plantparent_id) |
|
23 |
); |
|
24 |
END IF; |
|
25 |
END; |
|
26 |
$BODY$ |
|
27 |
LANGUAGE plpgsql IMMUTABLE STRICT |
|
28 |
COST 100 |
|
29 |
ROWS 10; |
Also available in: Unified diff
inputs/VegBank/: Added vegbank.~.utils.sql (which runs after vegbank.sql), for use by tables' create.sql scripts