I am trying to create the following function in PostgreSQL but get the following error. This is from a MySQL procedure that I need to convert to PostgreSQL. I am failing to convert the syntax to PostgreSQL. I am a beginner in PostgreSQL. Please assist me.
CREATE OR REPLACE FUNCTION public.usp_failed_analyze4()
RETURNS TABLE(status varchar) as
$BODY$
SET @maxdate = (SELECT MAX(analyzetime) FROM wp_analyze_history);
SET @maxdateint = (SELECT DATEDIFF(NOW() ,MAX(analyzetime)) FROM wp_analyze_history);
SET @STATUS = SELECT Status from wp_analyze_history WHERE Status NOT IN ('OK','Table is already up to date','The Analyze task DID NOT run!') AND analyzetime = @maxdate);
SET @STATUSNOTRUN = 'The Analyze task DID NOT run!';
IF @maxdateint > 7
THEN SELECT @STATUSNOTRUN;
ELSE SELECT @STATUS as "";
$BODY$
LANGUAGE sql;
error: ERROR: syntax error at or near "@"
Position: 109