Click here to Skip to main content
15,905,238 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create a postgresql function but it is giving the following error:
ERROR:  syntax error at or near ";"
LINE 16: end;
            ^
********** Error **********

ERROR: syntax error at or near ";"
SQL state: 42601
Character: 308


What I have tried:

create or replace function prcUDF(p_col1 integer,p_col2 text,p_col3 text)
returns void LANGUAGE 'plpgsql' as 
$$
begin
if(p_col2='1')
then
	UPDATE tblA set COLUMN12=p_col3 WHERE COLUMN0=p_col1;
ELSE IF (p_col2='2')
then
		UPDATE tblI set COLUMN11=p_col3 WHERE COLUMN0=p_col1;
end if;
	
end;
$$
Posted
Updated 22-Jun-17 3:56am
v2
Comments
RickZeeland 22-Jun-17 9:45am    
are you using pgadmin or psql ?

1 solution

There seems to be a problem with "else if", I think it needs to look like this:
SQL
CREATE FUNCTION public.test1(IN p_col1 integer, IN p_col2 text, IN p_col3 text) RETURNS void AS
$BODY$begin
if(p_col2='1') then
	UPDATE tblA set COLUMN12=p_col3 WHERE COLUMN0=p_col1;
end if;
if (p_col2='2') then
	UPDATE tblI set COLUMN11=p_col3 WHERE COLUMN0=p_col1;
end if;
end;
$BODY$
LANGUAGE plpgsql;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900