Project

General

Profile

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 plantconcept_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
13
    plantstatus.plantconcept_id
14
    , plantstatus.plantlevel
15
    , plantstatus.plantparent_id
16
    INTO plantconcept_id, plantlevel, plantparent_id
17
    FROM "VegBank".plantstatus
18
    WHERE plantstatus.plantconcept_id = plantconcept_id_
19
    ;
20
    -- Add this level to the list (output params' current values)
21
    RETURN NEXT;
22
    -- Recurse
23
    IF plantparent_id IS NOT NULL THEN
24
        RETURN QUERY (
25
            SELECT * FROM "VegBank"."plantconcept_ancestors"(plantparent_id)
26
        );
27
    END IF;
28
END;
29
$BODY$
30
  LANGUAGE plpgsql STABLE STRICT
31
  COST 100
32
  ROWS 10;
(4-4/4)