January 2019
Beginner
556 pages
14h 19m
English
PostgreSQL supports the IF and CASE statements, which allow for execution based on a certain condition. PostgreSQL supports the IF statement construct, as follows:
The CASE statement comes in two forms, as follows:
To understand the IF statement, let's suppose that we would like to convert the advertisement rank in to text, as follows:
CREATE OR REPLACE FUNCTION cast_rank_to_text (rank int) RETURNS TEXT AS $$DECLARE rank ALIAS FOR $1; rank_result TEXT;BEGIN IF rank = 5 THEN rank_result = 'Excellent'; ELSIF rank = 4 THEN rank_result ...
Read now
Unlock full access