Annotation: core.get_root_unit_id

CREATE OR REPLACE FUNCTION core.get_root_unit_id(integer)
RETURNS integer

Information: core.get_root_unit_id

Schema core
Function Name get_root_unit_id
Arguments integer
Owner postgres
Result Type integer
Description

Implementation: core.get_root_unit_id

CREATE OR REPLACE FUNCTION core.get_root_unit_id(integer)
 RETURNS integer
 LANGUAGE plpgsql
AS $function$
    DECLARE root_unit_id integer;
BEGIN
    SELECT base_unit_id INTO root_unit_id
    FROM core.compound_units
    WHERE compare_unit_id=$1;

    IF(root_unit_id IS NULL) THEN
        RETURN $1;
    ELSE
        RETURN core.get_root_unit_id(root_unit_id);
    END IF; 
END
$function$