I am new to postgresql. So, I am trying to create a function but I am getting the error message as
ERROR: syntax error at or near "IF" LINE 7: IF areaname = NULL OR pincode = NULL THEN
I refered this link.
CREATE FUNCTION location."fn_updateInArea"(area_id integer, areaname text, pincode text)
RETURNS boolean
LANGUAGE 'sql'
AS $BODY$
BEGIN
IF areaname IS NULL OR pincode IS NULL THEN
RETURNING false;
ELSE
UPDATE location.areainfo SET
area_name=CASE WHEN (areaname) IS NULL THEN (SELECT area_name from location.areainfo WHERE id=area_id) ELSE area_name END,
pin_code=CASE WHEN (pincode) IS NULL THEN (SELECT pin_code from location.areainfo WHERE id=area_id) ELSE pin_code END
WHERE id=area_id AND "deleteIndex"=false;
RETURNING true;
END IF;
END;
$BODY$;
ALTER FUNCTION location."fn_updateInArea"(integer, text, text)
OWNER TO postgres;
I know it would be silly error but do help me out.
Aucun commentaire:
Enregistrer un commentaire