IF Else Syntax and examples of conditional IF – Then – Else. CREATE OR REPLACE FUNCTION get_result(in p_name varchar(2)) RETURNS varchar AS $$ DECLARE v_name varchar(50); BEGIN if p_name = 'A' then v_name:='The name is A'; return v_name; else v_name:='The name...
IF / If Then Syntax and examples of conditional IF – Then. CREATE OR REPLACE FUNCTION get_result(in p_name varchar(2)) RETURNS varchar AS $$ DECLARE v_name varchar(50); BEGIN if p_name = 'A' then v_name:='The name is A'; return v_name; end if; END;...
PostgreSQL Conditionals Control Structures syntax: if then else, case when, return, exit, loop. Syntax IF expression THEN statement END IF; IF expression THEN statement_1 ELSE statement_2 END IF; IF expression_1 THEN statement_1 ELSIF expression_2 THEN statement_2 ELSE statement_3 END IF; CASE...
Add foreign key constraint to table How to add foreign key constraint to an existing table. Constraint syntax and example. Syntax ALTER TABLE table_name1 ADD CONSTRAINT fk_name FOREIGN KEY (column_name) REFERENCES table_name2 (unique_column_name); Example ALTER TABLE customers ADD CONSTRAINT fk_address FOREIGN...