Reputation: 3316
I'm using PostgreSQL with pgAdmin and I can't get a trigger function to work. However, as far as I am aware, you can return type trigger in PostgreSQL?
CREATE OR REPLACE FUNCTION validate_Cat()
RETURNS TRIGGER AS
$BODY$
BEGIN
-- CODE here
END;
$BODY$
LANGUAGE SQL;
CREATE TRIGGER validate_Cat
AFTER INSERT OR UPDATE ON Category
FOR EACH ROW execute procedure validate_Cat();
Upvotes: 12
Views: 5476
Reputation: 1
I got the same error below:
ERROR: SQL functions cannot return type trigger
When I tried to create the trigger function with LANGUAGE SQL
as shown below:
CREATE FUNCTION my_func() RETURNS trigger
LANGUAGE SQL -- Here
AS $$
$$;
But, I could create the trigger function with LANGUAGE plpgsql
without error as shown below:
CREATE FUNCTION my_func() RETURNS trigger
LANGUAGE plpgsql -- Here
AS $$
BEGIN
END;
$$;
In addition, I got the error below:
ERROR: SQL functions cannot return type event_trigger
When I tried to create the event trigger function with LANGUAGE SQL
as shown below:
CREATE FUNCTION my_func()
RETURNS event_trigger
LANGUAGE SQL -- Here
AS $$
$$;
But, I could create the event trigger function with LANGUAGE plpgsql
without error as shown below:
CREATE FUNCTION my_func()
RETURNS event_trigger
LANGUAGE plpgsql -- Here
AS $$
BEGIN
END;
$$;
Upvotes: 1