Category: PostgreSQL

PostgreSQL Loop – End Loop

LOOP Syntax and examples of conditional Loop – End Loop. CREATE OR REPLACE FUNCTION get_loop(in p_id numeric) RETURNS varchar AS $$ DECLARE j numeric; v_name varchar(50); BEGIN j:=0; FOR i in 1..p_id LOOP j:=j+1; v_name:='The count is: '||j; END LOOP; return...

PostgreSQL Case – When – Then

Case Syntax and examples of conditional Case – When – Then – Else. CREATE OR REPLACE FUNCTION get_case(in p_name varchar(2)) RETURNS varchar AS $$ DECLARE v_name varchar(50); BEGIN CASE WHEN p_name = 'T' then v_name:='The name is TEST'; return v_name; ELSE...

PostgreSQL IF – Elsif – Else syntax

In PostgreSQL, the IF-ELSIF-ELSE conditional statement allows you to execute different blocks of code based on certain conditions. This conditional statement is often used in PL/pgSQL, which is the procedural language supported by PostgreSQL. PL/pgSQL provides control structures like IF-ELSIF-ELSE to...