0

I am trying to create a function inside Postgres. For some reason my query works perfectly fine when I run it from inside the Query tool. Once I added the query to my function, I get the error

ERROR: syntax error at or near "DELETE"

Not sure what is the problem.

CREATE FUNCTION public.remove_email_header()
    RETURNS pg_trigger
    LANGUAGE 'plpgsql'

AS $BODY$
DELETE FROM public.spam_dictionary WHERE words LIKE '%FROM%';
$BODY$;

ALTER FUNCTION public.remove_email_header()
    OWNER TO postgres;
0

1 Answer 1

1

Two Things to note.

A plpgsql Postgres function uses BEGIN END

The plpgsql should not be quoted.

CREATE FUNCTION remove_email_header()
    RETURNS trigger
    LANGUAGE plpgsql

AS $BODY$
BEGIN
DELETE FROM public.spam_dictionary WHERE words LIKE '%FROM%';
END 
$BODY$;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.