What is causing the error here? If I’m not confusing anything, everything is done as it should
CREATE FUNCTION convert_temperature(temperature real, current_scale varchar DEFAULT 'Fahrenheit') RETURNS real AS $$
BEGIN
IF(current_scale = 'Celsius')
THEN RETURN temperatue*1.8+32
ELSE
RETURN (temperature-32)/1.8
END IF;
END
$$ LANGUAGE plpgsql
Gives a message:
ERROR: syntax error (example position: "RETURN")
I asked chatGPT where there could be a mistake, to which he answered me:
"There is no error in this function."
2
Answers
No need for pl/pgsql, SQL is good enough and faster. You can also use immutable because the function has no dependencies on any table.
When asked correctly at ChatGTP it answers:
The main changes made are:
Conclusion: Do not value ChatGPT as the source of anything (good or bad) when you ask the wrong question, you will not get a correct answer!