PostgreSQL ERROR: invalid input syntax for type boolean
PostgreSQL invalid input syntax for type boolean
The cause of error: Invalid input syntax for type boolean
is when values other than true or false are assigned to an boolean variable.
Wrong function
CREATE OR REPLACE FUNCTION update_test2 (p_old_name varchar, p_new_name varchar) RETURNS varchar AS $$ DECLARE v_result varchar(25):='OK'; v_boolean boolean:='t'; v2_boolean boolean; BEGIN if v_boolean = 't' then v2_boolean:=1+1; end if; return v_result; END; $$ LANGUAGE plpgsql;
select update_test2('name_1', 'name_3');
ERROR: invalid input syntax for type boolean
Correct function
CREATE OR REPLACE FUNCTION update_test2 (p_old_name varchar, p_new_name varchar) RETURNS varchar AS $$ DECLARE v_result varchar(25):='OK'; v_boolean boolean:='t'; v2_boolean numeric; BEGIN if v_boolean = 't' then v2_boolean:=1+1; end if; return v_result; END; $$ LANGUAGE plpgsql;
select update_test2('name_1', 'name_3');
Data Output: OK