Database Reference
In-Depth Information
RAISE NOTICE 'table is empty';
END IF;
END;
$$ LANGUAGE plpgsql;
The result can be seen using the following statement:
warehouse_db=# SELECT getRecords();
getRecords
------------
3
(1 row)
IF-THEN-ELSIF
If the case is of more than two alternatives to have in an IF-ELSE structure, then
IF-THEN-ELSIF will be the solution. The IF condition is tested until a successful IF
clause provides a true result, followed by the execution of associated statements and
inally passing control to the statement after END IF . This can be explained with the
help of the following example:
warehouse_db=# CREATE OR REPLACE FUNCTION nest_if(marks integer)
RETURNS text AS $$
DECLARE
grade text;
BEGIN
IF marks > 33 THEN
grade := 'PASS';
RETURN grade;
ELSIF marks = 33 THEN
grade := 'Average' ;
RETURN grade;
ELSIF marks < 33 THEN
grade := 'FAIL';
RETURN grade;
ELSE
-- this means he did not appear in exam
grade := 'DID NOT APPEAR IN EXAM';
RETURN grade;
END IF;
END;
$$ LANGUAGE plpgsql;
 
Search WWH ::




Custom Search