So I am creating a function in PostgreSQL for the first time and I am having a problem with the syntax or where exactly to put semicolons;
The function looks something like this:
CREATE OR REPLACE FUNCTION func(name1 TEXT, int1 INTEGER) RETURNS TEXT AS $$ DECLARE new_name TEXT; DECLARE int2 INTEGER; BEGIN ... Some SELECT FROM table queries ... IF int2 < int1 THEN new_name := func(new_name, int1); ELSE IF int2 = int1 THEN RETURN new_name; ELSE RETURN name1; END IF; END; $$ LANGUAGE plpgsql; If I try to submit this I get
ERROR: syntax error at or near ";" LINE 24: END; ^ If I remove the semicolon after END I get
ERROR: syntax error at end of input LINE 26: $$ LANGUAGE plpgsql; ^ And if I remove the semicolon after END and insert one after the $$ I get
$$; LANGUAGE plpgsql; ERROR: no language specified ERROR: syntax error at or near "LANGUAGE" LINE 1: LANGUAGE plpgsql; ^ Found the problem. Should have been ELSEIF instead of ELSE IF
ELSIFnotELSE IFpostgresql.org/docs/current/static/…