I’m trying to create a trigger in Postgresql, but the delimiter $$ isn’t recongnized. I’have small problems with the syntax of Postgresql after moving from MySql, so excuse my if this is just a very basic question.
I tried this code
CREATE TRIGGER trigger_name AFTER INSERT ON my_table FOR EACH ROW
$$
BEGIN
//Execute statement
END;
$$
LANGUAGE plpgsql;
But the error is
syntax error at or near "$$
BEGIN
//Execute statement
END;
$$"
2
Answers
When developing triggers in PostgreSQL, you are not required to use $$ delimiters. Instead, specify the trigger independently and create your trigger logic using plpgsql functions and the $$ delimiter. Try the code given under, I updated your code:
Hope it works 🙂
Here is the other way how you can achieve the same functionalty of trigger by first creating the function and then trigger.
In order to avoid function doesn’t exist error, you can run this code.